Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Saving over a range

I have the following code which makes a copy of a portion of my spreadsheet
at the "OK" command event and saves to the next available cell in the Data
worksheet.

Private Sub cmdOK_Click()
Dim rCell As Range
With Application.ThisWorkbook
Set rCell = .Worksheets("Data").Range("A65536").End(xlUp).Offs et(1, 0)
Worksheets("STD Calc").Range("B14:N33").Copy
rCell.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End With
Unload Me
End Sub

Prior to the OK button being clicked, the user has entered via a user form,
a beginning date for a two week payroll period. That date range and
coresponding data is then copied with the code above.
What I need to add in is a way to check for an occurance where the user
enters a date that already exists on the Data worksheet and the new copy is
saved right over the top of the old data that coresponds to that same date
range. This will happen if an error is made for a payroll period and the
user needs to correct it by going back to that payroll period. In other
words, I don't want to save the corrections to the next empty cell, I want it
to copy over the original data which was entered incorrectly and is now being
corrected.

How can I do that?

Thanks for any ideas.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Saving over a range

Give something like this a try...

Private Sub cmdOK_Click()
Dim rCell As Range
DimrFound as range

With Application.ThisWorkbook
Set rfound = .Worksheets("Data").Cells.Find(What:="TheDate", _

LookAt:=xlWhole, _

LookIn:=xlFormulas)
if rfound is nothing then
Set rCell = .Worksheets("Data").Range("A65536").End(xlUp).Offs et(1, 0)
else
setrCell = rFound
end if
Worksheets("STD Calc").Range("B14:N33").Copy
rCell.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End With
Unload Me
End Sub

--
HTH...

Jim Thomlinson


"TimN" wrote:

I have the following code which makes a copy of a portion of my spreadsheet
at the "OK" command event and saves to the next available cell in the Data
worksheet.

Private Sub cmdOK_Click()
Dim rCell As Range
With Application.ThisWorkbook
Set rCell = .Worksheets("Data").Range("A65536").End(xlUp).Offs et(1, 0)
Worksheets("STD Calc").Range("B14:N33").Copy
rCell.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End With
Unload Me
End Sub

Prior to the OK button being clicked, the user has entered via a user form,
a beginning date for a two week payroll period. That date range and
coresponding data is then copied with the code above.
What I need to add in is a way to check for an occurance where the user
enters a date that already exists on the Data worksheet and the new copy is
saved right over the top of the old data that coresponds to that same date
range. This will happen if an error is made for a payroll period and the
user needs to correct it by going back to that payroll period. In other
words, I don't want to save the corrections to the next empty cell, I want it
to copy over the original data which was entered incorrectly and is now being
corrected.

How can I do that?

Thanks for any ideas.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Saving over a range

Jim,

Would you help me understand a few things ( I am in way over my head with my
current understanding of VBA).
Tha following piece of your code:
(What:="TheDate", _

LookAt:=xlWhole, _

LookIn:=xlFormulas)


Are you saying something like; Look for August 7, 2006, if you find it copy
over the whole data. If not continue the copy at the next available cell?

I'm just not sure of the correct syntax to use.



"Jim Thomlinson" wrote:

Give something like this a try...

Private Sub cmdOK_Click()
Dim rCell As Range
DimrFound as range

With Application.ThisWorkbook
Set rfound = .Worksheets("Data").Cells.Find(What:="TheDate", _

LookAt:=xlWhole, _

LookIn:=xlFormulas)
if rfound is nothing then
Set rCell = .Worksheets("Data").Range("A65536").End(xlUp).Offs et(1, 0)
else
setrCell = rFound
end if
Worksheets("STD Calc").Range("B14:N33").Copy
rCell.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End With
Unload Me
End Sub

--
HTH...

Jim Thomlinson


"TimN" wrote:

I have the following code which makes a copy of a portion of my spreadsheet
at the "OK" command event and saves to the next available cell in the Data
worksheet.

Private Sub cmdOK_Click()
Dim rCell As Range
With Application.ThisWorkbook
Set rCell = .Worksheets("Data").Range("A65536").End(xlUp).Offs et(1, 0)
Worksheets("STD Calc").Range("B14:N33").Copy
rCell.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End With
Unload Me
End Sub

Prior to the OK button being clicked, the user has entered via a user form,
a beginning date for a two week payroll period. That date range and
coresponding data is then copied with the code above.
What I need to add in is a way to check for an occurance where the user
enters a date that already exists on the Data worksheet and the new copy is
saved right over the top of the old data that coresponds to that same date
range. This will happen if an error is made for a payroll period and the
user needs to correct it by going back to that payroll period. In other
words, I don't want to save the corrections to the next empty cell, I want it
to copy over the original data which was entered incorrectly and is now being
corrected.

How can I do that?

Thanks for any ideas.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Saving over a range

The code is trying got find the date somewhere on the sheet. This should
probably be narrowed down to a single column (probably D but I was not too
sure). If it finds the date then make rCell into the Date that was found. If
rfound is nothing then the date was not found so just use your original
code...
--
HTH...

Jim Thomlinson


"TimN" wrote:

Jim,

Would you help me understand a few things ( I am in way over my head with my
current understanding of VBA).
Tha following piece of your code:
(What:="TheDate", _

LookAt:=xlWhole, _

LookIn:=xlFormulas)


Are you saying something like; Look for August 7, 2006, if you find it copy
over the whole data. If not continue the copy at the next available cell?

I'm just not sure of the correct syntax to use.



"Jim Thomlinson" wrote:

Give something like this a try...

Private Sub cmdOK_Click()
Dim rCell As Range
DimrFound as range

With Application.ThisWorkbook
Set rfound = .Worksheets("Data").Cells.Find(What:="TheDate", _

LookAt:=xlWhole, _

LookIn:=xlFormulas)
if rfound is nothing then
Set rCell = .Worksheets("Data").Range("A65536").End(xlUp).Offs et(1, 0)
else
setrCell = rFound
end if
Worksheets("STD Calc").Range("B14:N33").Copy
rCell.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End With
Unload Me
End Sub

--
HTH...

Jim Thomlinson


"TimN" wrote:

I have the following code which makes a copy of a portion of my spreadsheet
at the "OK" command event and saves to the next available cell in the Data
worksheet.

Private Sub cmdOK_Click()
Dim rCell As Range
With Application.ThisWorkbook
Set rCell = .Worksheets("Data").Range("A65536").End(xlUp).Offs et(1, 0)
Worksheets("STD Calc").Range("B14:N33").Copy
rCell.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End With
Unload Me
End Sub

Prior to the OK button being clicked, the user has entered via a user form,
a beginning date for a two week payroll period. That date range and
coresponding data is then copied with the code above.
What I need to add in is a way to check for an occurance where the user
enters a date that already exists on the Data worksheet and the new copy is
saved right over the top of the old data that coresponds to that same date
range. This will happen if an error is made for a payroll period and the
user needs to correct it by going back to that payroll period. In other
words, I don't want to save the corrections to the next empty cell, I want it
to copy over the original data which was entered incorrectly and is now being
corrected.

How can I do that?

Thanks for any ideas.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Saving over a range

Jim,

OK, I'm almost there. I have plugged it in and it runs without error, only
it still copies to the next available cell. Here is what I have:

Dim rCell As Range
Dim rFound As Range
With Application.ThisWorkbook
Set rFound = .Worksheets("Data").Cells.Find(What:=("B1:B65536") ,
LookAt:=xlWhole, LookIn:=xlFormulas)
If rFound Is Nothing Then
Set rCell =
..Worksheets("Data").Range("A65536").End(xlUp).Off set(1, 0)
Else
Set rCell = rFound
End If
Worksheets("STD Calc").Range("B14:N34").Copy
rCell.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End With
Unload Me
End Sub

The date is in col "B" on the Data worksheet. I'm sure my "B1:B65536" is
not right. The date the user enters will be on a worksheet titled "STD Calc"
in cell C6. I need to have code to say "look at STD Calc cell C6, if that
date exists anywhere in Data, cells B1:B65536, then replace at that
location". I think that is what you are telling me, I just don't know how to
get it to work.


"Jim Thomlinson" wrote:

The code is trying got find the date somewhere on the sheet. This should
probably be narrowed down to a single column (probably D but I was not too
sure). If it finds the date then make rCell into the Date that was found. If
rfound is nothing then the date was not found so just use your original
code...
--
HTH...

Jim Thomlinson


"TimN" wrote:

Jim,

Would you help me understand a few things ( I am in way over my head with my
current understanding of VBA).
Tha following piece of your code:
(What:="TheDate", _

LookAt:=xlWhole, _

LookIn:=xlFormulas)


Are you saying something like; Look for August 7, 2006, if you find it copy
over the whole data. If not continue the copy at the next available cell?

I'm just not sure of the correct syntax to use.



"Jim Thomlinson" wrote:

Give something like this a try...

Private Sub cmdOK_Click()
Dim rCell As Range
DimrFound as range

With Application.ThisWorkbook
Set rfound = .Worksheets("Data").Cells.Find(What:="TheDate", _

LookAt:=xlWhole, _

LookIn:=xlFormulas)
if rfound is nothing then
Set rCell = .Worksheets("Data").Range("A65536").End(xlUp).Offs et(1, 0)
else
setrCell = rFound
end if
Worksheets("STD Calc").Range("B14:N33").Copy
rCell.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End With
Unload Me
End Sub

--
HTH...

Jim Thomlinson


"TimN" wrote:

I have the following code which makes a copy of a portion of my spreadsheet
at the "OK" command event and saves to the next available cell in the Data
worksheet.

Private Sub cmdOK_Click()
Dim rCell As Range
With Application.ThisWorkbook
Set rCell = .Worksheets("Data").Range("A65536").End(xlUp).Offs et(1, 0)
Worksheets("STD Calc").Range("B14:N33").Copy
rCell.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End With
Unload Me
End Sub

Prior to the OK button being clicked, the user has entered via a user form,
a beginning date for a two week payroll period. That date range and
coresponding data is then copied with the code above.
What I need to add in is a way to check for an occurance where the user
enters a date that already exists on the Data worksheet and the new copy is
saved right over the top of the old data that coresponds to that same date
range. This will happen if an error is made for a payroll period and the
user needs to correct it by going back to that payroll period. In other
words, I don't want to save the corrections to the next empty cell, I want it
to copy over the original data which was entered incorrectly and is now being
corrected.

How can I do that?

Thanks for any ideas.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Saving over a range

So you are looking in column B for the date... try this...

Set rFound = .Worksheets("Data").Columns("B").Find(What:=(???),
LookAt:=xlWhole, LookIn:=xlFormulas)


Replace ??? with the variable date value that is supplied by the user...
--
HTH...

Jim Thomlinson


"TimN" wrote:

Jim,

OK, I'm almost there. I have plugged it in and it runs without error, only
it still copies to the next available cell. Here is what I have:

Dim rCell As Range
Dim rFound As Range
With Application.ThisWorkbook
Set rFound = .Worksheets("Data").Cells.Find(What:=("B1:B65536") ,
LookAt:=xlWhole, LookIn:=xlFormulas)
If rFound Is Nothing Then
Set rCell =
.Worksheets("Data").Range("A65536").End(xlUp).Offs et(1, 0)
Else
Set rCell = rFound
End If
Worksheets("STD Calc").Range("B14:N34").Copy
rCell.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End With
Unload Me
End Sub

The date is in col "B" on the Data worksheet. I'm sure my "B1:B65536" is
not right. The date the user enters will be on a worksheet titled "STD Calc"
in cell C6. I need to have code to say "look at STD Calc cell C6, if that
date exists anywhere in Data, cells B1:B65536, then replace at that
location". I think that is what you are telling me, I just don't know how to
get it to work.


"Jim Thomlinson" wrote:

The code is trying got find the date somewhere on the sheet. This should
probably be narrowed down to a single column (probably D but I was not too
sure). If it finds the date then make rCell into the Date that was found. If
rfound is nothing then the date was not found so just use your original
code...
--
HTH...

Jim Thomlinson


"TimN" wrote:

Jim,

Would you help me understand a few things ( I am in way over my head with my
current understanding of VBA).
Tha following piece of your code:
(What:="TheDate", _

LookAt:=xlWhole, _

LookIn:=xlFormulas)

Are you saying something like; Look for August 7, 2006, if you find it copy
over the whole data. If not continue the copy at the next available cell?

I'm just not sure of the correct syntax to use.



"Jim Thomlinson" wrote:

Give something like this a try...

Private Sub cmdOK_Click()
Dim rCell As Range
DimrFound as range

With Application.ThisWorkbook
Set rfound = .Worksheets("Data").Cells.Find(What:="TheDate", _

LookAt:=xlWhole, _

LookIn:=xlFormulas)
if rfound is nothing then
Set rCell = .Worksheets("Data").Range("A65536").End(xlUp).Offs et(1, 0)
else
setrCell = rFound
end if
Worksheets("STD Calc").Range("B14:N33").Copy
rCell.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End With
Unload Me
End Sub

--
HTH...

Jim Thomlinson


"TimN" wrote:

I have the following code which makes a copy of a portion of my spreadsheet
at the "OK" command event and saves to the next available cell in the Data
worksheet.

Private Sub cmdOK_Click()
Dim rCell As Range
With Application.ThisWorkbook
Set rCell = .Worksheets("Data").Range("A65536").End(xlUp).Offs et(1, 0)
Worksheets("STD Calc").Range("B14:N33").Copy
rCell.PasteSpecial Paste:=xlValues
Application.CutCopyMode = False
End With
Unload Me
End Sub

Prior to the OK button being clicked, the user has entered via a user form,
a beginning date for a two week payroll period. That date range and
coresponding data is then copied with the code above.
What I need to add in is a way to check for an occurance where the user
enters a date that already exists on the Data worksheet and the new copy is
saved right over the top of the old data that coresponds to that same date
range. This will happen if an error is made for a payroll period and the
user needs to correct it by going back to that payroll period. In other
words, I don't want to save the corrections to the next empty cell, I want it
to copy over the original data which was entered incorrectly and is now being
corrected.

How can I do that?

Thanks for any ideas.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving a pre-determined range of cells as text? [email protected] Excel Discussion (Misc queries) 2 March 27th 07 11:58 PM
Saving the activecell range for later use Tim Coddington Excel Programming 0 December 12th 04 09:12 PM
Saving Range of Cells as Image File [email protected] Excel Programming 0 August 23rd 04 02:51 PM
Saving Range Locatoin into a Variable Jake Marx Excel Programming 4 September 10th 03 10:08 PM
Saving Range Locatoin into a Variable Bob Phillips[_5_] Excel Programming 0 September 10th 03 09:13 PM


All times are GMT +1. The time now is 12:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"