PC Review


Reply
Thread Tools Rate Thread

Convert macro that runs against entire column to run in current row

 
 
MiataDiablo@gmail.com
Guest
Posts: n/a
 
      12th Aug 2008
I'm using the following code to run through a column (F) combining
contents of two other columns and change font characteristics of the
first couple of characters. I have since created a form that allows
the user to enter information. When I click OK on my user form that
enters all of the info, I would like to call a macro that performs the
same thing but only on the row just added. Seems simple enough but I
can't seem to get my head around it. Any help is greatly appreciated.

Columns("F:F").Select
With Selection.Font
..Name = "Times New Roman"
..FontStyle = "Regular"
..Size = 11
End With
With ActiveSheet
r = ActiveSheet.Cells(.Rows.Count, 2).End(xlUp).Row
End With
For i = 2 To r
If IsEmpty(Cells(i, 4)) = True Then
Cells(i, 6).Value = Cells(i, 5).Value
With Cells(i, 6).Characters(Start:=1, Length:=3).Font
..FontStyle = "Bold"
End With
Else
Cells(i, 6).Value = Cells(i, 4).Value & ": " & Cells(i, 5).Value
With Cells(i, 6).Characters(Start:=1, Length:=2).Font
..FontStyle = "Bold"
End With
With Cells(i, 6).Characters(Start:=1, Length:=3).Font
..Size = 8
End With
End If
Next
Range("F1").Select
Selection.Font.Bold = True
End Sub
 
Reply With Quote
 
 
 
 
Wigi
Guest
Posts: n/a
 
      12th Aug 2008
*untested code*

Sub ddd()

Dim r As Long
Dim i As Long

With Columns("F:F").Font
.Name = "Times New Roman"
.FontStyle = "Regular"
.Size = 11
End With

r = Cells(Rows.Count, 2).End(xlUp).Row
With Cells(r, 6)
If IsEmpty(Cells(r, 4)) = True Then
.Value = Cells(r, 5).Value
.Characters(Start:=1, Length:=3).Font.FontStyle = "Bold"
Else
.Value = Cells(r, 4).Value & ": " & Cells(r, 5).Value
.Characters(Start:=1, Length:=2).Font.FontStyle = "Bold"
.Characters(Start:=1, Length:=3).Font.Size = 8
End If
End With

Range("F1").Font.Bold = True

End Sub




--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music


"(E-Mail Removed)" wrote:

> I'm using the following code to run through a column (F) combining
> contents of two other columns and change font characteristics of the
> first couple of characters. I have since created a form that allows
> the user to enter information. When I click OK on my user form that
> enters all of the info, I would like to call a macro that performs the
> same thing but only on the row just added. Seems simple enough but I
> can't seem to get my head around it. Any help is greatly appreciated.
>
> Columns("F:F").Select
> With Selection.Font
> ..Name = "Times New Roman"
> ..FontStyle = "Regular"
> ..Size = 11
> End With
> With ActiveSheet
> r = ActiveSheet.Cells(.Rows.Count, 2).End(xlUp).Row
> End With
> For i = 2 To r
> If IsEmpty(Cells(i, 4)) = True Then
> Cells(i, 6).Value = Cells(i, 5).Value
> With Cells(i, 6).Characters(Start:=1, Length:=3).Font
> ..FontStyle = "Bold"
> End With
> Else
> Cells(i, 6).Value = Cells(i, 4).Value & ": " & Cells(i, 5).Value
> With Cells(i, 6).Characters(Start:=1, Length:=2).Font
> ..FontStyle = "Bold"
> End With
> With Cells(i, 6).Characters(Start:=1, Length:=3).Font
> ..Size = 8
> End With
> End If
> Next
> Range("F1").Select
> Selection.Font.Bold = True
> End Sub
>

 
Reply With Quote
 
MiataDiablo@gmail.com
Guest
Posts: n/a
 
      13th Aug 2008
On Aug 12, 6:13*pm, Wigi <W...@discussions.microsoft.com> wrote:
> *untested code*
>
> Sub ddd()
>
> Dim r As Long
> Dim i As Long
>
> With Columns("F:F").Font
> * * .Name = "Times New Roman"
> * * .FontStyle = "Regular"
> * * .Size = 11
> End With
>
> r = Cells(Rows.Count, 2).End(xlUp).Row
> With Cells(r, 6)
> * * If IsEmpty(Cells(r, 4)) = True Then
> * * * * .Value = Cells(r, 5).Value
> * * * * .Characters(Start:=1, Length:=3).Font.FontStyle = "Bold"
> * * Else
> * * * * .Value = Cells(r, 4).Value & ": " & Cells(r, 5).Value
> * * * * .Characters(Start:=1, Length:=2).Font.FontStyle = "Bold"
> * * * * .Characters(Start:=1, Length:=3).Font.Size = 8
> * * End If
> End With
>
> Range("F1").Font.Bold = True
>
> End Sub
>
> --
> Wigihttp://www.wimgielis.be= Excel/VBA, soccer and music
>
>
>
> "MiataDia...@gmail.com" wrote:
> > I'm using the following code to run through a column (F) combining
> > contents of two other columns and change font characteristics of the
> > first couple of characters. *I have since created a form that allows
> > the user to enter information. *When I click OK on my user form that
> > enters all of the info, I would like to call a macro that performs the
> > same thing but only on the row just added. *Seems simple enough but I
> > can't seem to get my head around it. *Any help is greatly appreciated..

>
> > Columns("F:F").Select
> > With Selection.Font
> > ..Name = "Times New Roman"
> > ..FontStyle = "Regular"
> > ..Size = 11
> > End With
> > With ActiveSheet
> > r = ActiveSheet.Cells(.Rows.Count, 2).End(xlUp).Row
> > End With
> > For i = 2 To r
> > If IsEmpty(Cells(i, 4)) = True Then
> > Cells(i, 6).Value = Cells(i, 5).Value
> > With Cells(i, 6).Characters(Start:=1, Length:=3).Font
> > ..FontStyle = "Bold"
> > End With
> > Else
> > Cells(i, 6).Value = Cells(i, 4).Value & ": " & Cells(i, 5).Value
> > With Cells(i, 6).Characters(Start:=1, Length:=2).Font
> > ..FontStyle = "Bold"
> > End With
> > With Cells(i, 6).Characters(Start:=1, Length:=3).Font
> > ..Size = 8
> > End With
> > End If
> > Next
> > Range("F1").Select
> > Selection.Font.Bold = True
> > End Sub- Hide quoted text -

>
> - Show quoted text -


perfectamundo. I knew it would be easy. Many thanks
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
query runs on entire table not just current record =?Utf-8?B?c3RldmUyamg=?= Microsoft Access Queries 6 19th Jun 2007 11:43 AM
convert to upper case - entire column ? =?Utf-8?B?QWxpY2lh?= Microsoft Excel Misc 2 18th Mar 2007 03:25 PM
How to stop other macros while current macro runs Paul987 Microsoft Excel Programming 2 24th Apr 2006 05:15 PM
How do you convert an entire column into absolute value? =?Utf-8?B?TG9ycmFpbmU=?= Microsoft Excel Worksheet Functions 1 1st Feb 2006 05:58 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Microsoft Excel Programming 4 3rd May 2004 08:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:46 PM.