Help with Next code

santnok

Board Regular
Joined
Jan 10, 2014
Messages
97
Hi

I'am trying to do this.

Have a spreedsheet that have some columns like this the table under here


ABCDEFGHIJK
1NameDateFinishedNameDateFinishedNameDateFinished
2Roy23.4.2018xMette27.05.2018Hanne01.12.2018
3Mette27.5.2018Oskar30.04.2018xHelena18.07.2018
4Cecilie03.3.2018Hans01.02.2018x
5Roy17.5.2018
6
7

<tbody>
</tbody>

I'am trying to get a module in

Private Sub Worksheet_Change(ByVal Target As Range)


End Sub

to do a thing. If someone write a x to column C,G or K it will run this code I have writen (that dont work)

Code:
Dim lastrowc As String
Dim lastC As String
Dim c As Variant




Dim kollone1 As Variant: kollone1 = 3
Dim kollone2 As Variant: kollone2 = 7
Dim kollone3 As Variant: kollone3 = 11
Dim startRad As String: startRad = 3


lastrowc = Cells(Rows.Count, 1).End(xlUp).Row
'lastC = Cells(1, Columns.Count).End(xlToLeft).Column


Dim col1 As Variant


For c = startRad To lastrowc
For col1 = kollone1 To kollone1


    If Cells(c, col1) = "x" Then
        Cells(c, col1) = "X"
        Cells(c, col1).Select
        With Selection.Font
            .Name = "Calibri"
            .Size = 18
        End With
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
        End With
   
    End If
Next col1


Dim col2 As Variant


For col2 = kollone2 To kollone2


    If Cells(c, col2) = "x" Then
        Cells(c, col2) = "X"
        Cells(c, col2).Select
        With Selection.Font
            .Name = "Calibri"
            .Size = 18
        End With
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
        End With
   
    End If
Next col2


Dim col3 As Variant


For col3 = kollone3 To kollone3


    If Cells(c, col3) = "x" Then
        Cells(c, col3) = "X"
        Cells(c, col3).Select
        With Selection.Font
            .Name = "Calibri"
            .Size = 18
        End With
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
        End With
   
    End If
Next col3


Next c




End Sub

But this do not work, I'am also sure that I can write the code so it is not so long?

Hope that someone understand my problem here :)

<tbody>
</tbody>
 
Last edited:
Hi Fluff

Thank you so much for that code, and it worked like charm :) Have learned somthing new now :)
You're welcome & thanks for the feedback.
For the future please see post#10
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,216,075
Messages
6,128,657
Members
449,462
Latest member
Chislobog

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top