VBA trouble

Jstump

New Member
Joined
Oct 25, 2023
Messages
36
Office Version
  1. 365
Platform
  1. Windows
Can someone help me with why this is not working? It should be a triggered Macro that adds rows and data on my dash sheet in between rows 3 and 4 and copies the data into column A on Dash sheet from K4-K23 from Input sheet

Kane Macro.xlsm
GHIJK
1
2
3# manpower10Employee Employee name
41Clement, Vincent
52
63
74
85
96
107
118
129
1310
1411
1512
1613
1714
1815
1916
2017
2118
2219
2320
Input page
Cells with Data Validation
CellAllowCriteria
K4:K23List=Database!$A$2:$A$10


Kane Macro.xlsm
ABCDEFG
1
2
3Employee Name12-Jan13-Jan14-Jan15-Jan16-Jan
4total
5
6
Dash
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your "Input page" sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Enter a name in column K and press the ENTER key.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column <> 11 Then Exit Sub
    Application.ScreenUpdating = False
    With Sheets("Dash")
        .Rows(6).Insert
        .Range("A6") = Target
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 1
Solution
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your "Input page" sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Enter a name in column K and press the ENTER key.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    If Target.Column <> 11 Then Exit Sub
    Application.ScreenUpdating = False
    With Sheets("Dash")
        .Rows(6).Insert
        .Range("A6") = Target
    End With
    Application.ScreenUpdating = True
End Sub
Nothing was added or populated on the "dash" sheet.
 
Upvote 0
I tested the code using the data on the two sheets you posted and it worked correctly. Have you placed the macro in the worksheet code module as I described? Are you using the macro on the same data?
 
Upvote 0
I entered it correctly, just like you said. I added a tab and change the name to "Hours" but that was after it didnt work and i went back in the code and changed it there as well.

Kane Macro.xlsm
MNOP
1
2
3# manpower10Employee Employee name
41McCain, Austin
52Clement, Vincent
63McCain, Austin
74
85
96
107
118
129
1310
1411
1512
1613
1714
1815
1916
2017
2118
2219
2320
Input page
Cells with Data Validation
CellAllowCriteria
P4:P23List=Database!$A$2:$A$10


Kane Macro.xlsm
ABCDEFG
1
2
3Employee Name12-Jan13-Jan14-Jan15-Jan16-Jan
4total
5
6
7
8
Hours
 

Attachments

  • THis 1.png
    THis 1.png
    80.6 KB · Views: 5
Upvote 0
You've moved the target.column from K to P and so you need to amend the 11 accordingly (please also post your code directly in the thread [and preferably in code tags] rather than in an image)
 
Upvote 0
Beofre i moved it to column P it still was not working. However, now that the data was in column P i did adjust the 11 to 16 and it is working now. Thanks a bunch to everyone who helped.
 
Upvote 0
What could i add to make it delete the Row off of "hours" when data is deleted out of my P column on "input page"
 
Upvote 0
This is what i used to get it to auto delete as well. Thanks guys!

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge <> 1 Then Exit Sub
    If Target.Column = 16 Then
        Application.ScreenUpdating = False
        With Sheets("Hours")
            If Target.Value = "" Then
                .Rows(6).Delete
            Else
                .Rows(6).Insert
                .Range("A6") = Target.Value
            End If
        End With
        Application.ScreenUpdating = True
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,106
Messages
6,128,863
Members
449,473
Latest member
soumyahalder4

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