selecting non-contiguous cells

snazster

New Member
Joined
Jul 3, 2011
Messages
7
Hi,

I need help please selecting cells which are non-contiguous and which are the same for every row. The number of rows is variable, but I am unsure of the syntax for this.

I need to select the cells in column A, B, D, F and M for every row, one row at a time.

Any help is much appreciated.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Maybe like this

Code:
Sub test()
Dim i As Long
i = 10
Range("A1:A" & i & ",B1:B" & i & ",D1:D" & i & ",F1:F" & i & ",M1:M" & i).Select
End Sub
 
Upvote 0
Thanks for that.

I seem to have a problem with the following line of code when i have to select cells in columns I to L:

Code:
 ActiveChart.SeriesCollection(2).Values = "=Range(Cells(9, i), Cells(12, i))"
 
Last edited:
Upvote 0
Maybe

Code:
ActiveChart.SeriesCollection(2).Values = Range(Cells(9, i), Cells(12, i))
 
Upvote 0
Thanks, but with the code you suggest, I get the error:

Object variable or With block variable not set

Do you have any idea where my mistake is?

Code:
Sub graph()

Dim i As Integer
For i = 4 To 15

    
    
    Range("A1:A" & i & ",B1:B" & i & ",D1:D" & i & ",F1:F" & i & ",M1:M" & i).Select
    Range("AD4").Activate
    Charts.Add
    ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Sheets("Writing").Range("A1:A" & i & ",B1:B" & i & ",D1:D" & i & ",F1:F" & i & ",M1:M" & i) _
        , PlotBy:=xlRows
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection.NewSeries
    ActiveChart.SeriesCollection(2).Values = Range(Cells(9, i), Cells(12, i))
    


    ActiveChart.SeriesCollection(2).Name = "=""Target"""
    ActiveChart.SeriesCollection(3).Values = "=Writing!R4C39:R4C42"
    ActiveChart.SeriesCollection(3).Name = "=""Nat. Exp."""
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Writing"
    With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = "Writing"
        .Axes(xlCategory, xlPrimary).HasTitle = True
        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "End of Year"
        .Axes(xlValue, xlPrimary).HasTitle = True
        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Points"
    End With

    ActiveChart.SeriesCollection(2).Select
    ActiveChart.SeriesCollection(2).ChartType = xlLineMarkers
    ActiveChart.SeriesCollection(3).Select
    ActiveChart.SeriesCollection(3).ChartType = xlLineMarkers
    
    
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,448
Members
452,915
Latest member
hannnahheileen

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