Help adjusting code - offset row destination

rikvny02

Board Regular
Joined
Aug 9, 2022
Messages
78
Office Version
  1. 365
Platform
  1. Windows
Hello All Helpers
My code works great, However I'd like to add a second function. Once its added it overwrites the previous functions data. How can i adjust the code to add the data to the next available row?

Function vacation()

Dim sheetSource, shetDest As Worksheet
Dim rowSource, rowDest As Integer
Dim strcomments As String

Set sheetSource = Sheets("Vacation data")
rowSource = 4

Set shetDest = Sheets("Vacation load")
rowDest = 9

While sheetSource.Cells(rowSource, 4).Formula <> ""
strcomments = sheetSource.Cells(rowSource, 5).Value


boolAddToSheet = False

Select Case strcomments
Case Is >= 32
shetDest.Cells(rowDest, 6).Value = sheetSource.Cells(rowSource, 2).Value 'hours
shetDest.Cells(rowDest, 8).Value = sheetSource.Cells(rowSource, 5).Value 'employee id
shetDest.Cells(rowDest, 13).Value = sheetSource.Cells(rowSource, 8).Value 'shift
shetDest.Cells(rowDest, 14).Value = sheetSource.Cells(rowSource, 9).Value 'check group

rowDest = rowDest + 1



End Select

rowSource = rowSource + 1
Wend

End Function
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Just explain in a concise manner what you want to do.
 
Upvote 0
Hi @rikvny02

Change this line:
VBA Code:
rowDest = 9

For this:
VBA Code:
rowDest = shetDest.Range("H" & Rows.Count).End(3).Row + 1

I hope it's what you want.
😅
 
Upvote 1
Solution
Just explain in a concise manner what you want to do.
The function copies data from the Vacation Data (sheet) to the Vacation Load (sheet) only if there is data to transfer. My issue was if, the function was used more than once it was overwriting the data transferred to the vacation load. Hope this helps others in understanding what I was trying to accomplish. The below correction from @DanteAmor worked great.
 
Upvote 0

Forum statistics

Threads
1,215,365
Messages
6,124,513
Members
449,168
Latest member
CheerfulWalker

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