Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-12-2015, 08:27 AM
cc.caroline15 cc.caroline15 is offline Help with macros, what's wrong with my code?? Windows 8 Help with macros, what's wrong with my code?? Office 2013
Novice
Help with macros, what's wrong with my code??
 
Join Date: Jan 2015
Posts: 9
cc.caroline15 is on a distinguished road
Default Help with macros, what's wrong with my code??

Hello everyone I'm new to macros and this forum(:
I'm trying to create a macro that will:
get input from the user the location of the cell where the sum should appear. eg. user enters F6, macro will display the sum of cells B6:E6 in F6 and finish with the active cell being F6. Here is a snip of my code that I'm trying but it doesn't display the result. Can anyone help me? Thank you
Attached Images
File Type: png Capture.PNG (13.9 KB, 18 views)
Reply With Quote
  #2  
Old 01-12-2015, 10:27 AM
whatsup whatsup is offline Help with macros, what's wrong with my code?? Windows 7 64bit Help with macros, what's wrong with my code?? Office 2010 32bit
Competent Performer
 
Join Date: May 2014
Posts: 137
whatsup will become famous soon enough
Default

Hi

If I've got it right, you want to sumarize the last four cells to the left of the selected cell, that's how it works:
Code:
Sub Do_Sum()
With ActiveCell
    If .Column > 4 Then
        .FormulaR1C1 = "=Sum(RC[-4]:RC[-1])"
    End If
End With
End Sub
Cheers
Reply With Quote
  #3  
Old 01-12-2015, 07:25 PM
cc.caroline15 cc.caroline15 is offline Help with macros, what's wrong with my code?? Windows 8 Help with macros, what's wrong with my code?? Office 2013
Novice
Help with macros, what's wrong with my code??
 
Join Date: Jan 2015
Posts: 9
cc.caroline15 is on a distinguished road
Default

Hi,
What i'm trying to do is that when the user clicks the macro have a window pop up asking in what cell do you want to display the results of adding cells B6:E6 and end up with the active cell being the cell that is displaying the results. Please help me I'm so confuse my code is not working.
Thanks
Quote:
Originally Posted by whatsup View Post
Hi

If I've got it right, you want to sumarize the last four cells to the left of the selected cell, that's how it works:
Code:
Sub Do_Sum()
With ActiveCell
    If .Column > 4 Then
        .FormulaR1C1 = "=Sum(RC[-4]:RC[-1])"
    End If
End With
End Sub
Cheers
Reply With Quote
  #4  
Old 01-12-2015, 09:27 PM
macropod's Avatar
macropod macropod is offline Help with macros, what's wrong with my code?? Windows 7 64bit Help with macros, what's wrong with my code?? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If you're always summing B6:E6, why not have the user select the destination cell before running the macro? Much simpler than messing around with Input boxes, validating the input then changing the selection to suit.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 01-12-2015, 09:33 PM
cc.caroline15 cc.caroline15 is offline Help with macros, what's wrong with my code?? Windows 8 Help with macros, what's wrong with my code?? Office 2013
Novice
Help with macros, what's wrong with my code??
 
Join Date: Jan 2015
Posts: 9
cc.caroline15 is on a distinguished road
Default

Hi macropod,
I would love to do it like you said but unfortunately I have been ask to do it this specific way It's very frustrating ... :'(
Quote:
Originally Posted by macropod View Post
If you're always summing B6:E6, why not have the user select the destination cell before running the macro? Much simpler than messing around with Input boxes, validating the input then changing the selection to suit.
Reply With Quote
  #6  
Old 01-12-2015, 09:48 PM
macropod's Avatar
macropod macropod is offline Help with macros, what's wrong with my code?? Windows 7 64bit Help with macros, what's wrong with my code?? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

At its most basic you could use something like:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim StrAddr As String
StrAddr = Trim(InputBox("What is the Address of cell to update?", "Input Destination"))
On Error GoTo ErrExit
ActiveSheet.Range(StrAddr).Activate
ActiveCell.Value = "=SUM(B6:E6)"
ErrExit:
Application.ScreenUpdating = True
End Sub
Note that I haven't added any code to actually validate the address.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 01-12-2015, 10:04 PM
cc.caroline15 cc.caroline15 is offline Help with macros, what's wrong with my code?? Windows 8 Help with macros, what's wrong with my code?? Office 2013
Novice
Help with macros, what's wrong with my code??
 
Join Date: Jan 2015
Posts: 9
cc.caroline15 is on a distinguished road
Default

Thank you so much!! you were a big help!!
Quote:
Originally Posted by macropod View Post
At its most basic you could use something like:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim StrAddr As String
StrAddr = Trim(InputBox("What is the Address of cell to update?", "Input Destination"))
On Error GoTo ErrExit
ActiveSheet.Range(StrAddr).Activate
ActiveCell.Value = "=SUM(B6:E6)"
ErrExit:
Application.ScreenUpdating = True
End Sub
Note that I haven't added any code to actually validate the address.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
What's wrong with my loop? Irrma Word VBA 2 06-17-2014 06:25 AM
What's wrong with my code? ksigcajun Word VBA 3 05-19-2014 06:42 AM
Wrong hyphenation NobodysPerfect Word 1 02-04-2014 05:46 AM
Help with macros, what's wrong with my code?? Demo gone wrong RyanNIF Publisher 1 10-19-2011 05:55 AM
Help with macros, what's wrong with my code?? PLEASE HELP-wrong formatting???? bruce Word 10 04-10-2010 03:45 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:48 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft