Variable in a function in a macro

Tooch81

New Member
Joined
May 19, 2011
Messages
6
I've been writing macros for a while and for some reason I can't get a varaible in my formula to work correctly. This is a very simple macro this is just going to concatenate two cells (one static, the other a variable) and it's not working right. I've tried everythign I can think of and I'm stuck.

Thanks,

-Jeff-

- ---------------------------------------------

count1 = 2
sheet = 7

Sheets(sheet).Select

Do While count1 < 15
Cells(1, count1).Select
ActiveCell.Formula = CONCATENATE(Cells(1, 1).Value, Cells(count1, 5).Value)
count1 = count1 + 1
Loop

- ---------------------------------------------

I have tried everything know of to get this to work with no luck
ActiveCell.Formula = "Concatenate(A1,B5)"
The above code is the only way I can get it to work, but I need the B5 to be a variable.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Welcome to the board

ActiveCell.Formula = "= CONCATENATE(" & Cells(1, 1).Address & "," & Cells(count1, 5).Address & ")"
 
Upvote 0
How about
Code:
ActiveCell.Formula = "CONCATENATE(" & Cells(1,1).Address & "," & Cells(count1,5).Address & ")"
?
 
Upvote 0
Try

Code:
Do While count1 < 15
    Cells(1, count1).Formula = "=CONCATENATE(" & Cells(1, 1).Address & "," & Cells(count1, 5).Address & ")"
    count1 = count1 + 1
Loop
 
Upvote 0
I have been reading this borad for a couple years now and have never had to sign up until today. With that being said, a 2 minute turn around is AMAZING!!!

You guys are the best and I didnt' realize that I could seperate the "" within a formula.

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,671
Members
452,937
Latest member
Bhg1984

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