Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Location: New York City
Posts: 7
Default Copy/Paste using a macro that identifies occuoied range

I am working in the macro below. The purpose of the macro is to copy and paste a range from one file to another. So far that part of the macro as it is works perfect. However, I need to produce a spreadsheet in which I copy another range but I would like the macro to be able to determine if the range B5 is occupied them move and paste to range B9, if B9 is already occuoied, then paste to range B13, if B13 is occupaied then paste to range B17 tand continue the same pattern as necessary.

Sub CDamielM()
'
' CDamielM Macro
' Macro recorded 3/9/2006 by JAENJ
'

'
Range("B7").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Selection.Copy
Windows("Attendance.xls").Activate
Range("B5").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range("B9").Select
Windows("MASTER PROGRAM 2006bB.xls").Activate
Sheets("Check List").Select
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.setup
Mark
 
Posts: n/a
Default Copy/Paste using a macro that identifies occuoied range

I am not sure if you know how to use custom functions, but here is one
that will return the first range that is blank.
You must call the function by passing it the range you want to start
from, in your case, Range("B9"). consider the following example:

Sub test()

Dim Myrng As Range

Set Myrng = FindBlank(Range("B9"))
MsgBox "First Blank found @ " & Myrng.Address

End Sub

if you run this macro then the Message Box will display the Address of
the first cell found that is blank.

Here is the Function.

Function FindBlank(CurRng As Range) As Range

Dim TempRng As Range
Set TempRng = CurRng
Do
Debug.Print TempRng.Address
If TempRng < "" Then
Set FindBlank = TempRng.Offset(4, 0)
'Debug.Print "Checking next cell @ " & FindBlank.Address
Set TempRng = FindBlank
Else
FindBlank = TempRng
Exit Function
End If
Loop

End Function

If you have trouble give me a holler.

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
Macro to change Chart Range when inserting a column Mark Charts and Charting in Excel 1 September 13th 05 01:12 PM
Macro to copy range from Excel files in folder nc Excel Discussion (Misc queries) 1 June 15th 05 11:11 AM
Is it possible to set a variable range in a macro? Mary About this forum 0 June 12th 05 06:26 PM
Macro - define cell range for a sum function Fad Excel Discussion (Misc queries) 2 June 6th 05 12:40 PM
Macro for Show/Hide Range Bill Excel Discussion (Misc queries) 3 December 1st 04 05:33 PM


All times are GMT +1. The time now is 01:31 AM.

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"