LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Find next blank column with Macro

Hi All you very helpful guys
thanks for the quick posts and replies but it still keeps pasting over the
same column not sure if it the rest of the code doing it now but here it is
thanks again for all ytour help
kind regards
samijleeds

<code
Sub yes()

'Dim variables
Dim y As Long
Dim starta As String
Dim tr As Long, tc As Long
Dim sr As Long, sc As Long
Dim s As Worksheet, t As Worksheet
Dim n As Range
Dim strToFind As String
Dim flstc As Range
Dim LastCol As Long



'Setup
Application.ScreenUpdating = False

LastCol = Sheets("Finds").Cells(1, Columns.Count).End(xlToLeft).Column



Set t = Sheets("Finds")
Set s = Sheets("Draws")

strToFind = InputBox("What's The Number to Search for?")

'Get last used row in Target Sheet
t.Select
tr = Range("d65536").End(xlUp).Offset(1, 0).Row
tc = LastCol

'Start in search sheet at C4
s.Select
Range("c65536:j65536").Select

'Get 'yes'
y = Cells.Find(What:=strToFind, After:=Activecell, LookIn:=xlFormulas,
LookAt:= _
xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False).Activate
'Save start address for comparison
starta = Activecell.Address

'Label for goto (pseudo loop)
nextyes:

'Get row/col for copy paste
sr = Activecell.Row
sc = Activecell.Column

'Copy Column heading value to target sheet/cell in first column
'Cells(1, sc).Copy Destination:=t.Cells(tr, tc)

'Copy column "A" cell value to target sheet/cell
Cells(sr, 1).Copy Destination:=t.Cells(tr, tc + 1)

'Set destination = plus one row
tr = tr + 1
'Find next yes (til done)
y = Cells.FindNext(After:=Activecell).Activate
If Activecell.Address = starta Then
t.Select
Exit Sub
End If

'pseudo loop
GoTo nextyes


End Sub
<Code/


"Chip Pearson" wrote:

Try some code like the following:

Sub AAA()

Dim WS As Worksheet
Dim WhatRow As Long
Dim FirstUnusedColumnNum As Long
Dim FirstUnusedColumnRng As Range

Set WS = Worksheets("Sheet1") '<<<< CHANGE AS DESIRED
WhatRow = 1 '<<<< CHANGE AS DESIRED
With WS
Set FirstUnusedColumnRng = .Cells(WhatRow,
.Columns.Count).End(xlToLeft)
If FirstUnusedColumnRng.Column < 1 Then
Set FirstUnusedColumnRng = FirstUnusedColumnRng(1, 2)
End If
FirstUnusedColumnNum = FirstUnusedColumnRng.Column
End With
Debug.Print "First used range: " & FirstUnusedColumnRng.Address, _
"First unused column number: " & FirstUnusedColumnNum

End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
"samijleeds" wrote in message
...
Hi Guys

I have a question you may find a bit daft but it has me stumped.

I have a macro that finds the data I am looking for and pastes it into a
new
worksheet ok but what I would like it to do is look along the columns and
find the next blank column and paste the data there so that with each
paste
the macro will paste the new data into the next blank available column.

so first past will be in column A, then next paste in column B then next
in
C and so on I have this code at the moment but all it does is find the
same
column and over write the data that is already there

Dim LastCol As Long

LastCol = Sheets("Finds").Range("IV1").End(xlToLeft).Offset( 0, 1).Column

Ive searched through all the posts and have found it very very helpful for
other things but cant find anything on this

Thanks for you help in advance

SAMIJLeeds (West Yorkshire, UK)


 
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
how to find blank cell in column vinod New Users to Excel 1 April 3rd 09 08:27 PM
Trying to find the fourth blank cell in a column teepee[_3_] Excel Discussion (Misc queries) 7 April 28th 08 12:09 AM
Find First Non blank cell than find column header and return that value Silver Rose Excel Worksheet Functions 10 April 30th 07 05:56 PM
Find 1st blank cell in column & sum to the same row in another col Sharon Excel Worksheet Functions 2 March 7th 07 03:00 AM
Find first non-blank or non-zero in a column of data DerbyJim Excel Discussion (Misc queries) 3 January 16th 06 11:50 AM


All times are GMT +1. The time now is 12:50 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"