I want a Macro to do my work

Parra

Well-known Member
Joined
Feb 21, 2002
Messages
752
This is very tedious so I would like a macro to do the following.

I have the following data and I need it to be inserted in its related worksheet in a particular cell.

Column A, Column B
030, 2500
031, 3600
032, 4500
040, 1500
045, 8900
etc., etc

Column A is the name of the worksheet where I want the data in Column B inserted.

example. 030, 2500 I would go to worksheet 030 and in cell F12 enter 2500.

I know there is a way to automate this, but I don't know how, can someone help me.

Thanks
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
One question first: Do those commas actually appear in your data? If they do then get rid of them. Try the following code:

Dim rng As Range
Set rng = Intersect(ActiveSheet.UsedRange, Columns("A"))
For Each cell In rng
Worksheets(cell.Value).Range("F12").Value = ActiveSheet.Range("B" & cell.Row)
Next

Edit as needed.
 
Upvote 0
I think this does what you want. Give it a go and let me know:

Sub Macro1()


myRow = 1

Do Until Cells(myrow, 1) = ""
myName = Cells(myrow, 1)
Sheets("sheet" & myName).Cells(12, 6) = Cells(myRow, 2)
myRow = myRow + 1
Loop

'
End Sub



HTH

GaryB
 
Upvote 0
Hey guys thanks for the help, I tried both macros and I got the following error message for both.

Run Time Error '9'
Subscript out of range.

Please advice. Thanks
 
Upvote 0
Try Gary B's macro but modify the follwing line to excelude "sheet" & from:

Sheets("sheet" & myName).Cells(12, 6) = Cells(myRow, 2)

to:

Sheets(myName).Cells(12, 6) = Cells(myRow, 2)
 
Upvote 0
Hi Ricky, I tried your suggestion and I got the same error. Do you have any ideas why? I can't figure it out.

My vb knowledge is limited and I don't really understand the code. I know what it can do and is capable of.

Thanks
 
Upvote 0
The following code just worked for me.

Sub Macro1()
myRow = 1
Do Until Cells(myRow, 1) = ""
myName = Cells(myRow, 1)
Sheets(myName).Cells(12, 6) = Cells(myRow, 2)
myRow = myRow + 1
Loop
End Sub
 
Upvote 0
Hi Ricky I got the same message???? I don't know why??

I have the same data as I do in the first message and then I have the data in "Sheet 1" and then from left to right I have sheets 30, 31, 33, 40 and 45. This is actually a summary of the 85 sheets there really are, I am doing this on a test work book.

Any suggestions? Or info I can provide?

Thanks
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,167
Members
448,554
Latest member
Gleisner2

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