VBA - Copy Paste/Indirect Cell

Nordicrx8

Board Regular
Joined
Dec 10, 2015
Messages
144
Office Version
  1. 365
Platform
  1. Windows
Hey All, Happy New Year!

I'm trying to alter a current macro to be a bit more user friendly when needing a cell reference update.

The below code activates when a macro button is pressed. It's basically going to the SL ICR tab in the workbook, unmerging column C, and entering in market location into a specific cell. Problem being, these cell locations can change from time to time, resulting in me having to go into the code to manually update the cell the names are entered into.

The solution I came up with was to have the market name and cell location data on a separate tab called "Data Location". Market Name is in column Z, and Cell Location is in AA. I need help with VBA code to look on the Data location tab and copy the market name to it's assigned cell to the "SL ICR" Tab.

Any help on this would be greatly appreciated! :)

MarketICR
New England 1C18
Capitol 1C20
Canada 1C22
Great Lakes 1C24
Heartland 1C26
Upper Midwest 1C28
Greater Mid-Atlantic 1C30
Mid-South 1C36
Gulf Coast 1C38
Texoma 1C40
Florida 1C42
South Atlantic 1C48
Northern California 1C53
Southern California 1C59
Four Corners 1C65
Pacific Northwest 1C71


VBA Code:
Sub Convert_SL()
'
' Convert_SL Macro
'
    Sheets("SL ICR").Select
    Cells.Select
    Selection.UnMerge
        
    Range("C18").Select
    ActiveCell.FormulaR1C1 = "New England 1"
    Range("C20").Select
    ActiveCell.FormulaR1C1 = "Capitol 1"
    Range("C22").Select
    ActiveCell.FormulaR1C1 = "Canada 1"
    Range("C24").Select
    ActiveCell.FormulaR1C1 = "Great Lakes 1"
    Range("C26").Select
    ActiveCell.FormulaR1C1 = "Heartland 1"
    Range("C28").Select
    ActiveCell.FormulaR1C1 = "Upper Midwest 1"
    Range("C30").Select
    ActiveCell.FormulaR1C1 = "Greater Mid-Atlantic 1"
    Range("C36").Select
    ActiveCell.FormulaR1C1 = "Mid-South 1"
    Range("C38").Select
    ActiveCell.FormulaR1C1 = "Gulf Coast 1"
    Range("C40").Select
    ActiveCell.FormulaR1C1 = "Texoma 1"
    Range("C42").Select
    ActiveCell.FormulaR1C1 = "Florida 1"
    Range("C48").Select
    ActiveCell.FormulaR1C1 = "South Atlantic 1"
    Range("C53").Select
    ActiveCell.FormulaR1C1 = "Northern California 1"
    Range("C59").Select
    ActiveCell.FormulaR1C1 = "Southern California 1"
    Range("C65").Select
    ActiveCell.FormulaR1C1 = "Four Corners 1"
    Range("C71").Select
    ActiveCell.FormulaR1C1 = "Pacific Northwest 1"
    
End Sub
 
In that case the value in col AB is not a valid range reference.
Ohhhh - I got it! one market has a cell value in AA, but not in AB. it looks like the VBA code didn't like the blank field. I assigned it a random cell value and it cleared the error and everything populated. thanks again for your help! :)
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Duplicate reply - previous reply wasn't showing on my side. deleted.
 
Upvote 0
Ok, you can handle blank cells like
VBA Code:
         If Ary(r, 3) <> "" Then .Range(Ary(r, 3)).Value = Ary(r, 1)
 
Upvote 0

Forum statistics

Threads
1,224,803
Messages
6,181,055
Members
453,014
Latest member
Chris258

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