+ Reply to Thread
Results 1 to 4 of 4

Macro to effect cell based on column

Hybrid View

  1. #1
    Registered User
    Join Date
    11-20-2008
    Location
    UK
    Posts
    36

    Smile Macro to effect cell based on column

    I wasnt sure how to name this problem, but here goes.

    Option Explicit
    
    Sub Macro_Insert()
    '
    ActiveCell = ActiveCell & MyInputBox
    With ActiveCell.Characters(Start:=1, Length:=19).Font
    .Name = "Arial"
    .FontStyle = "Regular"
    .Size = 12
    .Strikethrough = False
    .Superscript = False
    .Subscript = False
    .OutlineFont = False
    .Shadow = False
    .Underline = xlUnderlineStyleNone
    .ColorIndex = xlAutomatic
    End With
    With ActiveCell.Characters(Start:=20, Length:=5).Font
    .Name = "Arial"
    .FontStyle = "Bold"
    .Size = 12
    .Strikethrough = False
    .Superscript = False
    .Subscript = False
    .OutlineFont = False
    .Shadow = False
    .Underline = xlUnderlineStyleNone
    .ColorIndex = xlAutomatic
    End With
    
    End Sub
    
    Function MyInputBox() As String
    
      While MyInputBox = "Enter your input text HERE" Or MyInputBox = ""
        MyInputBox = InputBox("This is my InputBox", "MyInputTitle", "Enter your input text HERE")
      Wend
      
    End Function
    The code above takes the value of a cell in on my worksheet and adds a further value ontop of it.

    The problem - I need to be able to use this formula on the rows numbered 5 by selecting only the column needed.

    Example;Column B is selected. When I activate the macro it will effect B5.
    Column CD is selected. When I activate it will effect CD5.

    And so on.

    Thanks in Advance!
    Last edited by Irprogram; 12-01-2008 at 04:00 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try this

    Option Explicit
    
    
    Sub Macro_Insert()
        Dim cl     As Range
        Set cl = Cells(5, ActiveCell.Column)
        cl = cl & MyInputBox
        With cl.Characters(Start:=1, Length:=19).Font
            .Name = "Arial"
            .FontStyle = "Regular"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        With cl.Characters(Start:=20, Length:=5).Font
            .Name = "Arial"
            .FontStyle = "Bold"
            .Size = 12
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
    
    End Sub
    
    Function MyInputBox() As String
    
        While MyInputBox = "Enter your input text HERE" Or MyInputBox = ""
            MyInputBox = InputBox("This is my InputBox", "MyInputTitle", "Enter your input text HERE")
        Wend
    
    End Function
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    11-20-2008
    Location
    UK
    Posts
    36
    royUK i'd like to say thank you

    It works :D

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Please mark your thread solved & rate the answer using the scales icon

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1