Macro that uses Cells in Column A being automatically reused for columns B,C,D...

VBAIntermediate

New Member
Joined
May 8, 2018
Messages
10
Hi All,

I have a macro that uses cell references from Column B, it uses a lot of cell references in Column B. Is it possible for me to set it up a macro or adjust it, so I could re-use that code for columns B, C, D ect keep the row references. Below is a hugely simplified version of what I coded. Problem is there are like 50 rows and I just need to have the macros repeat but using the column references from column C and D and E ect - I hope that makes sense


ABCD
1NAMEJohn
2AGE32
3HEIGHT6ft
4WEIGHT140

<tbody>
</tbody>

What I have, for example, is (ignore the blatant syntax issues)

Sub AgemultipliedByMadeupNumbers ()

Range("B2").Value =x
x*54654654 = y

End Sub

Is there a way for me to reuse that code but for column C and D, without copying and pasting it all, because my code is really long.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
In it's simplest form..... use an argument in your main subroutine.

Code:
Sub CallMainMacro()

AgemultipliedByMadeupNumbers ("B")
AgemultipliedByMadeupNumbers ("C")
AgemultipliedByMadeupNumbers ("D")

end sub


Sub AgemultipliedByMadeupNumbers(strColumnLetter)

 Range(strColumnLetter & "2").Value =x
 x*54654654 = y

 End Sub
 
Upvote 0
In it's simplest form..... use an argument in your main subroutine.

Code:
Sub CallMainMacro()

AgemultipliedByMadeupNumbers ("B")
AgemultipliedByMadeupNumbers ("C")
AgemultipliedByMadeupNumbers ("D")

end sub


Sub AgemultipliedByMadeupNumbers(strColumnLetter)

 Range(strColumnLetter & "2").Value =x
 x*54654654 = y

 End Sub

Thank you for this!

Is it possible for me to, when calling the subroutine, have the Column value be determined by what cell the cursor is in?
 
Upvote 0
Sure.... something like:

Call AgemultipliedByMadeupNumbers(Left(activecell.address,2))

There are other ways as well.....
 
Upvote 0

Forum statistics

Threads
1,215,617
Messages
6,125,867
Members
449,266
Latest member
davinroach

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top