Excel 2016
Hi
I have asked this question on a different forum but the user was unable to help..Here
I am not that proficient in VBA and I am doing my best to learn.
I have a workbook with two worksheets, “Sheet_1” and “Sheet_2”.
I am trying to write a VB macro that, if the condition “is not blank” is met on “Sheet_1” inserts a formula into a specific range of cells on “Sheet_2” worksheet.
How I would like it to work is the macro finds the first and last cells with data in “Sheet 1” Column A and use that to specify the range on “Sheet 2” Column A into which to enter the formula copied down the number of rows identified by the range from “Sheet_1”.
So if “Sheet 1” Column A has data in Cells A1 – A100 then the VB macro with enter the formula in “Sheet 2” Column A Cells A2 – A101 and then stop or exit. The formula should auto number the numeric references in the same way that it would if it was copied down manually. Sheet 2 has a header row hence the one row offset (A2 – A101)
I will need 8 different formulas, each entered in the 2nd row, of Columns A - H with the macro all using the same criteria to decided how many times down a column it should insert (if “Sheet 1” Column A has data in Cells A1 – A100 then the VB macro with enter the formula in “Sheet 2” Column A Cells A2 – A101 and then stop or exit.)
By this I mean:
Formula 1 goes into 2nd row of Column A
Formula 2 goes into 2nd row of Column B
Formula 3 goes into 2nd row of Column C
and so on.
For now I am trying to get it to just work on Formula 1 which seems a hard enough task for me before adding all 8 to the macro.
This is the code I have so far but I cannot get it to work.
This is above my skill level and I am unable to work out why the code is not working.
Hi
I have asked this question on a different forum but the user was unable to help..Here
I am not that proficient in VBA and I am doing my best to learn.
I have a workbook with two worksheets, “Sheet_1” and “Sheet_2”.
I am trying to write a VB macro that, if the condition “is not blank” is met on “Sheet_1” inserts a formula into a specific range of cells on “Sheet_2” worksheet.
How I would like it to work is the macro finds the first and last cells with data in “Sheet 1” Column A and use that to specify the range on “Sheet 2” Column A into which to enter the formula copied down the number of rows identified by the range from “Sheet_1”.
So if “Sheet 1” Column A has data in Cells A1 – A100 then the VB macro with enter the formula in “Sheet 2” Column A Cells A2 – A101 and then stop or exit. The formula should auto number the numeric references in the same way that it would if it was copied down manually. Sheet 2 has a header row hence the one row offset (A2 – A101)
I will need 8 different formulas, each entered in the 2nd row, of Columns A - H with the macro all using the same criteria to decided how many times down a column it should insert (if “Sheet 1” Column A has data in Cells A1 – A100 then the VB macro with enter the formula in “Sheet 2” Column A Cells A2 – A101 and then stop or exit.)
By this I mean:
Formula 1 goes into 2nd row of Column A
Formula 2 goes into 2nd row of Column B
Formula 3 goes into 2nd row of Column C
and so on.
For now I am trying to get it to just work on Formula 1 which seems a hard enough task for me before adding all 8 to the macro.
This is the code I have so far but I cannot get it to work.
VBA Code:
Sub InsertFormulasTest()
Dim Answer As VbMsgBoxResult
Dim xRow As Long
Dim ws As Worksheet: Set ws = Sheets("Sheet1")
Dim ws2 As Worksheet: Set ws2 = Sheets("Sheet2")
Answer = MsgBox("Insert Formula", vbYesNo, "Insert formula test")
If Answer = vbYes Then
Application.ScreenUpdating = False
xRow = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1
ws2.Range("A1:A").CurrentRegion.ClearContents
xRow = 1
ws2.Range("A2:A10").Formula = "=IF(Sheet1A1>"""", ""Has Data"",""No Data"")"
End If
End Sub
This is above my skill level and I am unable to work out why the code is not working.