Formula that includes a cell reference in code

MeisterConrad

New Member
Joined
Jan 17, 2017
Messages
39
Office Version
  1. 2007
Can anyone tell me what's wrong with this bit?
On the "AccountInfoSheet, I have a range for the user to input names for different accounts. -So "currently", the list is blank. So I'm trying to make a code that inserts a formula into the merged cell D9:N9 on the "current" sheet (NOT the AccountInfoSheet).
This whole bit is part of a loop that relies on the counter n. So the next time around, we'd be on a different worksheet, and the last line of code would refer to the next item in the list of account names.

VBA Code:
Dim b As Range
b = Sheets("AccountInfoSheet").Range("E4:E23")
       n = n + 1
' So at this point, n=4, which makes n-3=1.  This makes (or is supposed to make) the next line refer to the first item in the range E4:E23, 
' and insert the cell address for that item into the formula.  
' The formula gets input into the merged cell D9:N9.
Range ("D9:N9).Formula = " = CONCATENATE("Click here to data-sort this ", "&Range(b)(n-3).Address&", " Ledger")"

The only reason it needs to be a formula is so that the user can enter the account names in the list at a later date, and those names get input into D9:N9 on the NON-"AccountInfoSheet"- sheets. If there's a better way to do THAT, I'm all ears.

Thanks for any advice.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
This may not solve all of your problems, but you need to Set a variable to a range.
VBA Code:
Dim b As Range
Set b = Sheets("AccountInfoSheet").Range("E4:E23")
 
Upvote 0
Solution

Forum statistics

Threads
1,214,944
Messages
6,122,387
Members
449,080
Latest member
Armadillos

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