Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7
Default Macro:- Find first blank cell and write text

Hi All,
I have a spreadsheet in 9 Columns (A to I) and, at the moment, 772 Rows.
I want to write a macro that:-
Finds the first blank cell in column B, (ie B772)
Writes some text into that cell,
Steps to the next cell on the right, (ie C772)
Writes some text into that cell,
Steps to the next cell on the right, (ie D772)
Writes some text into that cell,
Steps across 2 cells to the right, (ie F772)
Writes some text into that cell,
Steps across 3 cells to the right and 1 down, (ie I773)
Writes some text into that cell.
End the macro.

The text being written to the cells will be the same on all occasions.

Can anyone help pleaese, many thanks.
--
Mac Macdonald
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default Macro:- Find first blank cell and write text

Set the Security level to low/medium in (Tools|Macro|Security). 'Launch VBE
using short-key Alt+F11. Insert a module and paste the below code. Save. Get
back to Workbook. Tools|Macro|Run MacroTest(). Please try and feedback

Sub MacroTest()

Dim strData As String
Dim lngLastRow As Long

strData = "Some text"
lngLastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row + 1

Range("B" & lngLastRow) = strData
Range("C" & lngLastRow) = strData
Range("D" & lngLastRow) = strData
Range("F" & lngLastRow) = strData
Range("I" & lngLastRow + 1) = strData

End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Mac0001UK" wrote:

Hi All,
I have a spreadsheet in 9 Columns (A to I) and, at the moment, 772 Rows.
I want to write a macro that:-
Finds the first blank cell in column B, (ie B772)
Writes some text into that cell,
Steps to the next cell on the right, (ie C772)
Writes some text into that cell,
Steps to the next cell on the right, (ie D772)
Writes some text into that cell,
Steps across 2 cells to the right, (ie F772)
Writes some text into that cell,
Steps across 3 cells to the right and 1 down, (ie I773)
Writes some text into that cell.
End the macro.

The text being written to the cells will be the same on all occasions.

Can anyone help pleaese, many thanks.
--
Mac Macdonald

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,124
Default Macro:- Find first blank cell and write text

You may like this. You don't say what text you need to input for each cell.
Sub putindata()
With Cells(Cells(Rows.Count, "a").End(xlUp).Row + 1, "a")
.Value = "aaa"
.Offset(, 1) = "bbb"
.Offset(, 2) = "ccc"
.Offset(, 3) = "dd"
.Offset(, 5) = "ff"
.Offset(1, 8) = "i773"
End With
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Mac0001UK" wrote in message
...
Hi All,
I have a spreadsheet in 9 Columns (A to I) and, at the moment, 772 Rows.
I want to write a macro that:-
Finds the first blank cell in column B, (ie B772)
Writes some text into that cell,
Steps to the next cell on the right, (ie C772)
Writes some text into that cell,
Steps to the next cell on the right, (ie D772)
Writes some text into that cell,
Steps across 2 cells to the right, (ie F772)
Writes some text into that cell,
Steps across 3 cells to the right and 1 down, (ie I773)
Writes some text into that cell.
End the macro.

The text being written to the cells will be the same on all occasions.

Can anyone help pleaese, many thanks.
--
Mac Macdonald


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7
Default Macro:- Find first blank cell and write text


--
Mac Macdonald


"Jacob Skaria" wrote:

Set the Security level to low/medium in (Tools|Macro|Security). 'Launch VBE
using short-key Alt+F11. Insert a module and paste the below code. Save. Get
back to Workbook. Tools|Macro|Run MacroTest(). Please try and feedback

Sub MacroTest()

Dim strData As String
Dim lngLastRow As Long

strData = "Some text"
lngLastRow = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row + 1

Range("B" & lngLastRow) = strData
Range("C" & lngLastRow) = strData
Range("D" & lngLastRow) = strData
Range("F" & lngLastRow) = strData
Range("I" & lngLastRow + 1) = strData

End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Mac0001UK" wrote:

Hi All,
I have a spreadsheet in 9 Columns (A to I) and, at the moment, 772 Rows.
I want to write a macro that:-
Finds the first blank cell in column B, (ie B772)
Writes some text into that cell,
Steps to the next cell on the right, (ie C772)
Writes some text into that cell,
Steps to the next cell on the right, (ie D772)
Writes some text into that cell,
Steps across 2 cells to the right, (ie F772)
Writes some text into that cell,
Steps across 3 cells to the right and 1 down, (ie I773)
Writes some text into that cell.
End the macro.

The text being written to the cells will be the same on all occasions.

Can anyone help pleaese, many thanks.
--
Mac Macdonald


Jacob,

Many thanks. Your solution works beautifully, so simple, so elegant, when
you know how, I have a lot to learn.

Cheers,
Mac
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
How to write a macro that will clear validated cells to blank? JAbels001 Excel Worksheet Functions 3 November 20th 08 05:20 PM
how do I write a macro to show the find dialog box in excel 2003 evets Excel Discussion (Misc queries) 1 July 6th 08 01:11 PM
macro to find the last blank cell in col. A peyman Excel Discussion (Misc queries) 16 September 17th 07 11:10 PM
how do I write macro to sum numbers up to next blank line? Art Nittskoff Excel Discussion (Misc queries) 2 January 2nd 07 04:56 PM
Find a non-blank cell and bring back text a in same row Rod Excel Worksheet Functions 12 March 24th 05 09:43 PM


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

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

About Us

"It's about Microsoft Excel"