copy information in a row,after value changes(to another worksheet)

AJIESPEDAS

New Member
Joined
Jun 3, 2023
Messages
19
Office Version
  1. 2019
Platform
  1. MacOS
good day gentlemen,
im a excel noob trying to use vba to copy certain data to another worksheet.i have been trying all the vba line on the internet, and i cant seem to make it work like it suppose to. so Im stuck leaving to register to mr.excel to get help.
based on the picture i shared, local date dictate for a line 13 from (C13 to N13) to be copy to another worksheet (HOUR).each and everytime local date change in relation to the line 13, it will copy to HOUR worksheet to the next line without overwriting the previous one.
example

local date 01/01/23-shane bunyak , 00;40 and so on till line N13
local date 02/01/23-danial ,00;30 and so on till line N13

please help me, i have come to a dead end with my noob knowledge.
 

Attachments

  • Screenshot 2023-06-03 at 5.33.23 PM.png
    Screenshot 2023-06-03 at 5.33.23 PM.png
    98.4 KB · Views: 15
mine got this when i double click on the column O12, highlight on the arrow that i draw

Hi, Sorry for the inconvenience, i didnt think the dictionary exist properly. here's the revise code

All are possible for adjustment :), only the conditions needed to state well so i can re-adjust it.

existing name with the same date, what're you going to deal with it? do you want to copy to the next row? or overwrite the existing values through the new one? for now the code is doing nothing with it

Thanks for bear with me, looking forward to hear you soon :)

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Dim dict As New Dictionary

 B = Range(Cells(Target.Row, "C"), Cells(Target.Row, Target.Column - 1)).Value
 
With Sheets("hour")
A = .Range("b3:l" & .Cells(Rows.Count, "a").End(xlUp).Row).Value
End With

For i = 1 To UBound(A, 1)
If Not dict.Exists(A(i, 2)) And A(i, 2) <> "" Then
    dict.Add A(i, 1) & A(i, 2), i
End If
Next i

ld = Sheets("voyage report").Range("h6").Value

    If B(1, 1) <> "" Then
 
        If Not dict.Exists(ld & B(1, 1)) Then
        With Sheets("hour")
            lrow = .Cells(Rows.Count, "g").End(xlUp).Row + 1
             .Cells(lrow, "a").Value = "LOCAL DATE"
            .Cells(lrow, "b").Value = ld
            .Cells(lrow, "c").Resize(1, UBound(B, 2)).Value = B
        End With
        End If
 
    End If
End Sub
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi, Sorry for the inconvenience, i didnt think the dictionary exist properly. here's the revise code

All are possible for adjustment :), only the conditions needed to state well so i can re-adjust it.

existing name with the same date, what're you going to deal with it? do you want to copy to the next row? or overwrite the existing values through the new one? for now the code is doing nothing with it

Thanks for bear with me, looking forward to hear you soon :)

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Dim dict As New Dictionary

 B = Range(Cells(Target.Row, "C"), Cells(Target.Row, Target.Column - 1)).Value
 
With Sheets("hour")
A = .Range("b3:l" & .Cells(Rows.Count, "a").End(xlUp).Row).Value
End With

For i = 1 To UBound(A, 1)
If Not dict.Exists(A(i, 2)) And A(i, 2) <> "" Then
    dict.Add A(i, 1) & A(i, 2), i
End If
Next i

ld = Sheets("voyage report").Range("h6").Value

    If B(1, 1) <> "" Then
 
        If Not dict.Exists(ld & B(1, 1)) Then
        With Sheets("hour")
            lrow = .Cells(Rows.Count, "g").End(xlUp).Row + 1
             .Cells(lrow, "a").Value = "LOCAL DATE"
            .Cells(lrow, "b").Value = ld
            .Cells(lrow, "c").Resize(1, UBound(B, 2)).Value = B
        End With
        End If
 
    End If
End Sub
hi, i tried the the newest code that you provide getting closer and closer to perfection. i just found out that the row 15 still getting overwrite; and not properly copy the value. < and when copy value jumble up it does not overwriting the previous data, it only happen on row15,the last one


>>existing name with the same date, what're you going to deal with it? do you want to copy to the next row? or overwrite the existing values through the new one? for now the code is doing nothing with it <-i think overwriting the existing value make it looks profesional.
 
Upvote 0
Hi, Please try the code below. Please do make sure the formats starting from row 3 below column A to N (Hour sheets) are same

1686045738656.png


vr fixup (1).xlsm
ABCDEFGHIJKLMN
1STAFF NOSTAFF NAMEP1P2P1/USTOTAL
2DAYNIGHTDAYNIGHTDAY NIGHT
3LOCAL DATE5/1/2023FO0096THARMA RAJAH00:0100:0200:2000:2000:0202:31ER1
4LOCAL DATE5/1/2023FO0120ABDUL AZIZ B AMRAN00:4000:0700:0000:0900:10312:31ER2
5LOCAL DATE5/1/20230DATO SAKHTIAR00:0100:0032:32ER3
6LOCAL DATE5/1/20230MOHD ALIZAN00:0201:2300:00312:31ER4
7LOCAL DATE6/1/2023FO0096THARMA RAJAH00:0100:0200:2000:2000:0202:31TEST1
8LOCAL DATE6/1/2023FO0120ABDUL AZIZ B AMRAN00:4000:0700:0000:0900:10312:31TEST12
9LOCAL DATE6/1/20230DATO SAKHTIAR00:0100:0032:32TEST3
10LOCAL DATE6/1/20230MOHD ALIZAN00:0201:2300:00312:31TEST4
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
HOUR


VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Dim dict As New Dictionary

 B = Range(Cells(Target.Row, "C"), Cells(Target.Row, Target.Column - 1)).Value
 
With Sheets("hour")
A = .Range("b3:l" & .Cells(Rows.Count, "a").End(xlUp).Row).Value
End With

For i = 1 To UBound(A, 1)
If Not dict.Exists(A(i, 3)) And A(i, 3) <> "" Then
    dict.Add A(i, 1) & A(i, 3), i + 2
End If
Next i

ld = Sheets("voyage report").Range("h6").Value

    If B(1, 1) <> "" Then
 
        If Not dict.Exists(ld & B(1, 2)) Then
        lrow = Sheets("hour").Cells(Rows.Count, "g").End(xlUp).Row + 1
        Else
        lrow = dict(ld & B(1, 2))
        End If
      
        With Sheets("hour")
         .Cells(lrow, "a").Value = "LOCAL DATE"
        .Cells(lrow, "b").Value = ld
        .Cells(lrow, "c").Resize(1, UBound(B, 2)).Value = B
         End With
    End If

End Sub
 
Last edited:
Upvote 0
Hi, Please try the code below. Please do make sure the formats starting from row 3 below column A to N (Hour sheets) are same

View attachment 93019

vr fixup (1).xlsm
ABCDEFGHIJKLMN
1STAFF NOSTAFF NAMEP1P2P1/USTOTAL
2DAYNIGHTDAYNIGHTDAY NIGHT
3LOCAL DATE5/1/2023FO0096THARMA RAJAH00:0100:0200:2000:2000:0202:31ER1
4LOCAL DATE5/1/2023FO0120ABDUL AZIZ B AMRAN00:4000:0700:0000:0900:10312:31ER2
5LOCAL DATE5/1/20230DATO SAKHTIAR00:0100:0032:32ER3
6LOCAL DATE5/1/20230MOHD ALIZAN00:0201:2300:00312:31ER4
7LOCAL DATE6/1/2023FO0096THARMA RAJAH00:0100:0200:2000:2000:0202:31TEST1
8LOCAL DATE6/1/2023FO0120ABDUL AZIZ B AMRAN00:4000:0700:0000:0900:10312:31TEST12
9LOCAL DATE6/1/20230DATO SAKHTIAR00:0100:0032:32TEST3
10LOCAL DATE6/1/20230MOHD ALIZAN00:0201:2300:00312:31TEST4
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
HOUR


VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Dim dict As New Dictionary

 B = Range(Cells(Target.Row, "C"), Cells(Target.Row, Target.Column - 1)).Value
 
With Sheets("hour")
A = .Range("b3:l" & .Cells(Rows.Count, "a").End(xlUp).Row).Value
End With

For i = 1 To UBound(A, 1)
If Not dict.Exists(A(i, 3)) And A(i, 3) <> "" Then
    dict.Add A(i, 1) & A(i, 3), i + 2
End If
Next i

ld = Sheets("voyage report").Range("h6").Value

    If B(1, 1) <> "" Then
 
        If Not dict.Exists(ld & B(1, 2)) Then
        lrow = Sheets("hour").Cells(Rows.Count, "g").End(xlUp).Row + 1
        Else
        lrow = dict(ld & B(1, 2))
        End If
     
        With Sheets("hour")
         .Cells(lrow, "a").Value = "LOCAL DATE"
        .Cells(lrow, "b").Value = ld
        .Cells(lrow, "c").Resize(1, UBound(B, 2)).Value = B
         End With
    End If

End Sub
hi RudRud,
i believe i can make it work...thanks a million! for your help...
 
Upvote 0

Forum statistics

Threads
1,215,140
Messages
6,123,269
Members
449,093
Latest member
Vincent Khandagale

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