Marcoteo
New Member
- Joined
- Nov 7, 2021
- Messages
- 2
- Office Version
- 2016
- Platform
- Windows
Hello everyone, I'm new member and I'm new in this Excel Macro World.
Is a week that i trying to do something with VB macro, I searched and read everywhere, also here (i think is best forum this one) , to find the solution for my problem but trying this and that nothing look working, so, the last solution, here we are.
So, my situation :
I have two Worksheets, and i need to copy the data wrote in the ws 1 (called wsMain) to the second ws (called wsHistory).
In wsHistory i want create a table formed to 4 colums, any time i copy 4 data from wsMain i have a new row in wsHistory.
The copy from wsMain i want that happen when the value of a single cell ("E2") change.
In the E2 i have formula (=E3) with no format (General Format), and E3 is (=MOUNTH(TODAY()). My target before was directly E3 but i saw than not worked.
Ok so this is my VB macro
Private Sub Worksheet_Change(ByVal Target As Range)
Dim wsMain As Worksheet, wsHistory As Worksheet
Dim NextRow As Long
' Cambia nome Main con la pagina in cui viene scritta la tabella
Set wsMain = Sheets("DatiEsterni")
Set wsHistory = Sheets("Storico&Grafici")
' Ogni volta che la cella Target cambia
If Target.Address(0, 0) = "E2" Then
' Crea una nuova riga
NextRow = wsHistory.Cells(Rows.Count, 4).End(xlUp).Row + 1
' E copia questi valori nella nuova riga
wsHistory.Range("A" & NextRow).Value = wsMain.Range("D2").Value
wsHistory.Range("B" & NextRow).Value = wsMain.Range("B7").Value
wsHistory.Range("C" & NextRow).Value = wsMain.Range("B8").Value
wsHistory.Range("D" & NextRow).Value = wsMain.Range("B9").Value
End If
End Sub
All working good but the problem is that :
1 - He don't copy the 4 datas automaticaly when E2 change, but i have to select E2 and push Enter. And this is not what i want because i would like that he copy automaticaly when the mounth change.
2- Another thing i would like do ,but online solutions looks not working for me, is that in wsHistory where i want create database when he copy from wsMain he put the result under the rows wrote before and I tryed in all ways to shift old result and put the new row upper the others.
Is a week that i trying to do something with VB macro, I searched and read everywhere, also here (i think is best forum this one) , to find the solution for my problem but trying this and that nothing look working, so, the last solution, here we are.
So, my situation :
I have two Worksheets, and i need to copy the data wrote in the ws 1 (called wsMain) to the second ws (called wsHistory).
In wsHistory i want create a table formed to 4 colums, any time i copy 4 data from wsMain i have a new row in wsHistory.
The copy from wsMain i want that happen when the value of a single cell ("E2") change.
In the E2 i have formula (=E3) with no format (General Format), and E3 is (=MOUNTH(TODAY()). My target before was directly E3 but i saw than not worked.
Ok so this is my VB macro
Private Sub Worksheet_Change(ByVal Target As Range)
Dim wsMain As Worksheet, wsHistory As Worksheet
Dim NextRow As Long
' Cambia nome Main con la pagina in cui viene scritta la tabella
Set wsMain = Sheets("DatiEsterni")
Set wsHistory = Sheets("Storico&Grafici")
' Ogni volta che la cella Target cambia
If Target.Address(0, 0) = "E2" Then
' Crea una nuova riga
NextRow = wsHistory.Cells(Rows.Count, 4).End(xlUp).Row + 1
' E copia questi valori nella nuova riga
wsHistory.Range("A" & NextRow).Value = wsMain.Range("D2").Value
wsHistory.Range("B" & NextRow).Value = wsMain.Range("B7").Value
wsHistory.Range("C" & NextRow).Value = wsMain.Range("B8").Value
wsHistory.Range("D" & NextRow).Value = wsMain.Range("B9").Value
End If
End Sub
All working good but the problem is that :
1 - He don't copy the 4 datas automaticaly when E2 change, but i have to select E2 and push Enter. And this is not what i want because i would like that he copy automaticaly when the mounth change.
2- Another thing i would like do ,but online solutions looks not working for me, is that in wsHistory where i want create database when he copy from wsMain he put the result under the rows wrote before and I tryed in all ways to shift old result and put the new row upper the others.