Copy, Paste, Replace VBA Code

thankyouvince

New Member
Joined
Jul 12, 2017
Messages
12
Hello guys so I have this formula on say A2.

=IFERROR(IF(INDIRECT("'CAR 002'!G25")="x","Employer's Request",IF(INDIRECT("'CAR 002'!L25")="x","Contractor Request",IF(INDIRECT("'CAR 002'!R25")="x","Consultant Request"))),"")

How can i copy this formula on A3 but changing CAR 002 to CAR 003 and so fort using VBA macro. (CAR 004 on A4...)

Thank you so much guys!
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Is there a need for VBA code? Put this in A2 and copy down.

=IFERROR(IF(INDIRECT("'CAR " & TEXT(ROWS($A$1:A2),"000") & "'!G25")="x","Employer's Request",IF(INDIRECT("'CAR " & TEXT(ROWS($A$1:A2),"000") & "'!L25")="x","Contractor Request",IF(INDIRECT("'CAR " & TEXT(ROWS($A$1:A2),"000") & "'!R25")="x","Consultant Request"))),"")
 
Upvote 0
Is there a need for VBA code? Put this in A2 and copy down.

=IFERROR(IF(INDIRECT("'CAR " & TEXT(ROWS($A$1:A2),"000") & "'!G25")="x","Employer's Request",IF(INDIRECT("'CAR " & TEXT(ROWS($A$1:A2),"000") & "'!L25")="x","Contractor Request",IF(INDIRECT("'CAR " & TEXT(ROWS($A$1:A2),"000") & "'!R25")="x","Consultant Request"))),"")

Thanks for the quick reply but YES i'm afraid I do need Macro because I have this button in Sheet1 that creates new sheet namely CAR 00x and the same time inserts new row below. Now this newly created sheet is linked in Sheet1 through the formula above.

Eg. i clicked button. (Sheet1 a1 value = 001)
- on sheet1 a2 value = 002 b3 = my formula
-sheet CAR 002 will be created
-and so on. a3=003 b3=formula above but CAR 003

Hope you get my point sorry for bad explanation. :(
 
Upvote 0
When you click the button, is it safe to say that the sheet it creates is based on the last row in column A? For example, if A1:A10 are populated, the next sheet would be "CAR 011"?

If so, try:

Code:
Public Sub thankyouvince()
Dim oWS     As Worksheet
Dim nWS     As Worksheet
Dim LR      As Long

Application.ScreenUpdating = False
Set oWS = ActiveSheet
LR = oWS.Range("A" & Rows.Count).End(xlUp).Row + 1
Set ws = Sheets.Add
ws.Name = "CAR " & Format(LR, "000")
oWS.Range("A" & LR).Formula = "=IFERROR(IF('" & ws.Name & "'!G25=""x"",""Employer's Request"",IF('" & ws.Name & "'!L25=""x"",""Contractor Request"",IF('" & ws.Name & "'!R25=""x"",""Consultant Request""))),"""")"
oWS.Activate
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,844
Members
449,471
Latest member
lachbee

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