Mr_Ragweed2
Board Regular
- Joined
- Nov 11, 2022
- Messages
- 145
- Office Version
- 365
- Platform
- Windows
Hello and thanks,
This should be easy, i just need a jumpstart i think. I have a code that copies certain data from one worksheet and pastes it to the finalrow on another worksheet. This is initiated via a button click and everything works great. My issue is that if you push the button twice you get the data twice and what i would want to do is to overwrite any previously copied data. The paste location is dynamic (hence the finalrow statement.) What i need to do is look for a value in column c, if it does not exist then proceed with my current code. If it does exist then i want to overwrite it with what is currently being copied. My code is below:
As you can see i tried to start a little segment there that is half in laymans terms (i have to lay things out logically in regular words and then convert those steps to vba since i don't do this often.)
Any help is appreciated.
This should be easy, i just need a jumpstart i think. I have a code that copies certain data from one worksheet and pastes it to the finalrow on another worksheet. This is initiated via a button click and everything works great. My issue is that if you push the button twice you get the data twice and what i would want to do is to overwrite any previously copied data. The paste location is dynamic (hence the finalrow statement.) What i need to do is look for a value in column c, if it does not exist then proceed with my current code. If it does exist then i want to overwrite it with what is currently being copied. My code is below:
VBA Code:
Dim ThisFinal As Long
Dim I As Integer
Dim OSumWS As Worksheet
Dim DekalbWS As Worksheet
Set OSumWS = Sheets("Order Summary")
Set DekalbWS = Sheets("Dekalb Seed Order Form")
ThisFinal = OSumWS.Cells(Rows.Count, 17).End(xlUp).Row 'new line
For I = 19 To 31
If DekalbWS.Cells(I, 3).Value <> "" Then
With Application.Intersect(DekalbWS.Rows(I).EntireRow, DekalbWS.Range("C:U"))
.UnMerge
.Copy
End With
'12-19-22 Need to look first to see if vendor already exists. if "yes" then overwrite based on location, if "no" then proceed as normal.
'Dim Overwrite As Integer ???
If OSumWS.Cells(I, 3).Value = "Dekalb" Then
'set Overwrite = the range i found "dekalb" in
'then maybe i Else If the rest of this?
OSumWS.Cells(ThisFinal + 1, 2).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ThisFinal = OSumWS.Cells(Rows.Count, 2).End(xlUp).Row 'new line
End If
Next I
As you can see i tried to start a little segment there that is half in laymans terms (i have to lay things out logically in regular words and then convert those steps to vba since i don't do this often.)
Any help is appreciated.