Increment in excel vba

I have a data in excel which I want to make a VBA script to copy it into a new worksheet but in a different way.
For example, I have this in sheet1 in A1~A3 cells.

Adam(A1)
Sam(A2)
Smith(A3)

I want to use these cells and create the following in another worksheet using refedit control.

Adam(A1)
Adam(A2)
Adam(A3)
Adam(A4)
Sam(A5)
Sam(A6)
Sam(A7)
Sam(A8)
Smith(A9)
Smith(A10)
Smith(A11)
Smith(A12)

I have refedit control in place in VBA script, but I’m not sure how to increment cell numbers to make it copy and paste into a new worksheet. I would like to use refedit control so that I can assign any cells and make it copy and repeat itself. How do I do this in VBA script?

Dr. belisarius's user avatar

asked Dec 7, 2010 at 21:59

js0823's user avatar

Check out the Range Rows, Cells, and Address properties. This should help. Your question is too vague for a direct answer.


(This will get you started.)

Range.Row Property

http://msdn.microsoft.com/en-us/library/bb221550(office.12).aspx

Returns the number of the first row of the first area in the range. Read-only Long.

Example

For Each rw In Worksheets("Sheet1").Rows
    If rw.Row Mod 2 = 0 Then
        rw.RowHeight = 4
    End If
Next rw 

Community's user avatar

answered Dec 8, 2010 at 15:06

AMissico's user avatar

AMissicoAMissico

21.4k6 gold badges76 silver badges106 bronze badges

2

To increment cells in Excel VBA, you can use the Offset-property of the Range-object, e.g.

ActiveCell.Offset(1, 1).Select

will select the cell one row down and one column to the right of the active cell.

answered Dec 10, 2010 at 7:10

Geoffrey's user avatar

GeoffreyGeoffrey

5,40710 gold badges42 silver badges77 bronze badges

To add to Geoffrey’s answer about active cell — it would also require that you activate the sheet you are looking to input your values if it is a different sheet from the one that is currently active. Additionally you would have to activate a cell to use activecell and the activecell offset property.
For example

     'Activates the name of the sheet you would like to activate
    Sheets("Sheet2").Activate  

    'Activates cell A1
    Range("A1").Activate

    'Activates cell one row down, one column right
    ActiveCell.Offset(1,1).Select  

   'if current sheet is not activate you just do Sheets("Sheet2").Range("A1").Activate

The offset property of ActiveCell refers to other cells based off of the current active cell.

For example-

Offset(row,column) —

First Argument -Positive values as the first argument refer you to rows below the current active cell and Negative values refer you to rows above the current active cell

Second Argument-Positive values as the second argument refer you to columns right of the current active cell and Negative values refer you to columns left the current active cell

answered Jan 7, 2013 at 16:00

drD's user avatar

drDdrD

211 gold badge1 silver badge8 bronze badges

Содержание

  1. How do I increment cell in Excel VBA script?
  2. 3 Answers 3
  3. Range.Row Property
  4. Example
  5. Increment VBA int variable in-line — like i++ ?
  6. shell_l_d
  7. Excel Facts
  8. shell_l_d
  9. shell_l_d
  10. shell_l_d
  11. Norie
  12. shell_l_d
  13. Norie
  14. Incrementing the row and Deleting a row using vba IN EXCEL
  15. 2 Answers 2
  16. How can I increment column value in excel VBA?
  17. 2 Answers 2
  18. Increment in excel vba

How do I increment cell in Excel VBA script?

I have a data in excel which I want to make a VBA script to copy it into a new worksheet but in a different way. For example, I have this in sheet1 in A1

I want to use these cells and create the following in another worksheet using refedit control.

I have refedit control in place in VBA script, but I’m not sure how to increment cell numbers to make it copy and paste into a new worksheet. I would like to use refedit control so that I can assign any cells and make it copy and repeat itself. How do I do this in VBA script?

3 Answers 3

Check out the Range Rows , Cells , and Address properties. This should help. Your question is too vague for a direct answer.

(This will get you started.)

Range.Row Property

Returns the number of the first row of the first area in the range. Read-only Long.

Example

To increment cells in Excel VBA, you can use the Offset-property of the Range-object, e.g.

will select the cell one row down and one column to the right of the active cell.

To add to Geoffrey’s answer about active cell — it would also require that you activate the sheet you are looking to input your values if it is a different sheet from the one that is currently active. Additionally you would have to activate a cell to use activecell and the activecell offset property. For example

The offset property of ActiveCell refers to other cells based off of the current active cell.

First Argument -Positive values as the first argument refer you to rows below the current active cell and Negative values refer you to rows above the current active cell

Second Argument-Positive values as the second argument refer you to columns right of the current active cell and Negative values refer you to columns left the current active cell

Источник

Increment VBA int variable in-line — like i++ ?

shell_l_d

Board Regular

Excel Facts

MrExcel MVP

No, there isn’t, but .

shell_l_d

Board Regular

Hmmm interesting thanks (speedy reply too ).
that’d be similar to (better than) using a string array & a for loop too (have >20 columns).

I also need to fill the table with data for each of the headings, like doing this (again for >20 columns & more complex/longer formulas)

shell_l_d

Board Regular

shell_l_d

Board Regular

Bugger. I added line continuations in the code to make it more readable. however I need to add another 6 columns (headings & formula’s) however I can only add 1 extra (25 line continuations) if I keep it in the format above, as I get the error: Too many line continuations.

Might have to split it into 3 lots (all, sla, non-sla).

Norie

Well-known Member

Why not put some of the headers on the same row?

Then you wouldn’t need all that line continuation.

You could even ‘group’ related headers, something like this.

shell_l_d

Board Regular

Norie

Well-known Member

I understand about readability but a separate line for each item in quite a large array seems, to me anyway, a bit much.

Whenever I use Array with arrays that size I try and make them readable, but I also try to make sure they fit in 1 screen.

You could end up with a column of string values going down the centre with nothing to show what they actually are.

I wouldn’t recommend using what I suggest for much else.

For example if it was a long SQL statement in the code, building it up by line by line using concatentation can be a good idea.

In that case it can actually help debugging the code — it’s much easier to work with an SQL statement that’s been broken down to it’s individual parts/clauses.

By the way what are those formulas meant to do?

Источник

Incrementing the row and Deleting a row using vba IN EXCEL

The above statement selects the 25th row of H column.Now The thing I want to know is, How do i increment the row putting H constant? yeah I have seen these on the google $h24 where column stays constant and row keeps on incrementing.

But i have to increment it from H25 to the end I dont know where does H column end. how do i make that?We can declare a variable right using VBA and incremenet it?

The actual Task I need to do is I have to check rows from H25 to the end and get their values to my VBA and make some calcutaions then right it back to them Im stucked at incrementing the rows.And could anyone please let me know the macro to delete a row from the vba itself?Thank you

2 Answers 2

I believe you can provide some further details about how this range is supposed to looks like. When you mean «have to check rows from H25 to the end and» what’s the END here?

If you’re manually copying the formula down, it will automatically goes until the last row with values in column G. Is that your case? I’m not assuming the H rows below row 25 already have some values. Is this the case?

If you use as END the last row with values in column G, you can use Selection.AutoFill .

If you already have values in column H and want to go through them, you can define a dynamic range and loop through it in VBA.

To define a dynamic range: Add a new range, based in this formula (you may need to adapt it according to your needs, obviously) =OFFSET(Sheet1!$H$25,0,0,COUNTA(Sheet1!$H:$H),1)

And then, in VBA, go through it.

In time: To delete an entire row in Excel, you’ll use

Источник

How can I increment column value in excel VBA?

I have 2 excel sheets one is mapping and other is soneri. I want to increment the values of Column D in soneri sheet which was get by lookup function. What is the mistake in my code?

Only first 2 rows are correct of my outcome else are wrong.

Below is my code

«WORKING CODE EDITED»

Sub ButtonClick() Dim soneriWs As Worksheet, mappingWs As Worksheet Dim sonerilastrow As Long, mappinglastrow As Long, i As Long Dim datarange As Range, assetrange As Range, b As Range Dim entry As Variant

2 Answers 2

Rows.Count returns that number of rows for the active sheet. Try changing these two lines:

Also remember to clear any errors that might occur, otherwise you can run into trouble. Insert this before the Sub returns:

I see you removed your «on error» statement.

I would also recommend that you force variable decalarations, as I can see you use undeclared variables, which will also get you into trouble sooner or later. Insert this as the first line in all modules:

Please post test data «as text» next time to help people help you. Here is a solution. I uncommented your if statement, as it seem to not update the first record.

If you are new to VBA I recommend that you learn how to use the Scripting.Dictionary.

Your loop is only made for a single match of the Asset class.

There are a few problems here, but the if x > 2 approach would really only work if there was only one counter. Then we could substitute + 1 with something like + x — 2 (since we start at 3 for this part of the code).
But what you need is a counter that resets each time there is a new Asset class.

Another way of writing it would be

But it’s using much the same approach.

These however expect the data to be sorted on the «I» column, since the counter will reset if there is another asset in between.
If you want it to work even when not sorted, you could use something like countIf, like so: (Replacing the loop)

Источник

Increment in excel vba

dizzy1984
Дата 16.3.2010, 15:49 (ссылка) | (нет голосов) Загрузка .

Опытный

Профиль
Группа: Участник
Сообщений: 675
Регистрация: 15.2.2007

Репутация: нет
Всего: 25

ViterAlex
Дата 16.3.2010, 15:53 (ссылка) | (нет голосов) Загрузка .

Шустрый

Профиль
Группа: Участник
Сообщений: 94
Регистрация: 7.10.2009
Где: Харьков

Репутация: 7
Всего: 7

Код
Public Function Inc (n As Variant)
Inc = n +1
End Function
dizzy1984
Дата 17.3.2010, 16:33 (ссылка) | (нет голосов) Загрузка .

Опытный

Профиль
Группа: Участник
Сообщений: 675
Регистрация: 15.2.2007

Репутация: нет
Всего: 25

1. Публиковать ссылки на вскрытые компоненты

2. Обсуждать взлом компонентов и делиться вскрытыми компонентами

  • Несанкционированная реклама на форуме запрещена
  • Пожалуйста, давайте своим темам осмысленный, информативный заголовок. Вопль «Помогите!» таковым не является.
  • Чем полнее и яснее Вы изложите проблему, тем быстрее мы её решим.
  • Оставляйте свои записи в «Книге отзывов о работе администрации»
  • А вот тут лежит FAQ нашего подраздела

Если Вам понравилась атмосфера форума, заходите к нам чаще!
С уважением mihanik и staruha.

Правила форума «Программирование, связанное с MS Office»
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Программирование, связанное с MS Office | Следующая тема »

[ Время генерации скрипта: 0.1037 ] [ Использовано запросов: 21 ] [ GZIP включён ]

Источник

Adblock
detector

You can use the Step keyword in Excel VBA to specify a different increment for the counter variable of a loop. Explanation: The code lines between For and Next will be executed three times. For i = 1, Excel VBA enters the value 100 into the cell at the intersection of row 1 and column 1.

How do I increment a Fill Down in Excel?

Automatically fill increment cells with Autofill function

  1. Then in the cell below the starting number, here is A2, and type the second number you want into it.
  2. Then select the A1 and A2, and drag the autofill handle down until below cells are filled with the increment numbers as you need.

How do you auto increment in Excel without dragging?

Quickly Fill Numbers in Cells without Dragging

  1. Enter 1 in cell A1.
  2. Go to Home –> Editing –> Fill –> Series.
  3. In the Series dialogue box, make the following selections: Series in: Columns. Type: Linear. Step Value: 1. Stop Value: 1000.
  4. Click OK.

How do you increment an alphanumeric value in Excel?

Select a column or a range that you want to fill the cells with increment alphanumeric string.

  1. Then click Kutools > Insert > Insert Sequence Number, see screenshot:
  2. In the Insert Sequence Number dialog box, please click New button to expand the dialog, see screenshot:

How do you increment in Java?

1) Post-Increment (i++): we use i++ in our statement if we want to use the current value, and then we want to increment the value of i by 1. 2) Pre-Increment(++i): We use ++i in our statement if we want to increment the value of i by 1 and then use it in our statement.

What is a finite increment?

A formula expressing the increment of a function in terms of the value of its derivative at an intermediate point. The finite-increments formula can also be written in the form f(x+Δx)−f(x)=f′(x+θΔx)Δx,0<θ<1.

How do I increment a range of cells in Excel?

Basically I am updating a sheet and some of the cells in that range will be empty until I add data so when I click on my “Update Sheet” button it will increment the values by one for cells with data in and then when I add new data and update those cells will begin their incrementation. thanks in advance!! Select range. Press Ctrl+1.

How to increase the number of rows in a column in Excel?

Note: In the formula, $A$3 is the absolute reference to the first cell you need to get in a certain column, the number 1 indicates the row of cell that the formula is entered, and 3 is the number of rows you will increase. 2. Keep selecting the result cell, then drag the Fill Handle down the column to get all needed results.

How to fill across a row with formula in Excel?

For filling across a row, you need to: Select a blank cell, enter formula =OFFSET ($C$1,0, (COLUMN ()-1)*3) into the Formula Bar, then press the Enter key. See screenshot: 2. Then drag the result cell across the row to get the needed results. Note: In the formula, $C$1 is the absolute reference to the first cell you need to get in a certain row,…

How to increment date by month/year/7 days in Excel?

Increment date by month/year/7days with Fill Series utility. With the Fill Series utility, you can increment date by 1 month, 1 year or a week. 1. Select a blank cell and type the starting date. 2. Select a range including starting date, and click Home > Fill > Series. See screenshot:

...
          Dim iRow As Integer, iCol As Integer, iTotalCols As Integer
              
2         iRow = 1
3         iCol = 1
          
          ' Array of Headings
          ' All
4         Call AddToArray(sHeadings, "Total")
5         Call AddToArray(sHeadings, "RespTm PASS")
6         Call AddToArray(sHeadings, "RespTm %")
7         Call AddToArray(sHeadings, "ResolTm PASS")
8         Call AddToArray(sHeadings, "ResolTm %")
9         Call AddToArray(sHeadings, "OVERALL PASS")
10        Call AddToArray(sHeadings, "OVERALL %")
11        Call AddToArray(sHeadings, "ReWorks")
12        Call AddToArray(sHeadings, "CSR PASS")
          ' SLA
13        Call AddToArray(sHeadings, "SLA Total")
14        Call AddToArray(sHeadings, "SLA RespTm PASS")
15        Call AddToArray(sHeadings, "SLA RespTm %")
16        Call AddToArray(sHeadings, "SLA ResolTm PASS")
17        Call AddToArray(sHeadings, "SLA ResolTm %")
18        Call AddToArray(sHeadings, "SLA OVERALL PASS")
19        Call AddToArray(sHeadings, "SLA OVERALL %")
20        Call AddToArray(sHeadings, "SLA ReWorks")
21        Call AddToArray(sHeadings, "SLA CSR PASS")
          ' Non-SLA
22        Call AddToArray(sHeadings, "Non-SLA Total")
23        Call AddToArray(sHeadings, "Non-SLA RespTm PASS")
24        Call AddToArray(sHeadings, "Non-SLA RespTm %")
25        Call AddToArray(sHeadings, "Non-SLA ResolTm PASS")
26        Call AddToArray(sHeadings, "Non-SLA ResolTm %")
27        Call AddToArray(sHeadings, "Non-SLA OVERALL PASS")
28        Call AddToArray(sHeadings, "Non-SLA OVERALL %")
29        Call AddToArray(sHeadings, "Non-SLA ReWorks")
30        Call AddToArray(sHeadings, "Non-SLA CSR PASS")
          
          ' Array of Formulas
          ' All
31        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>" + scSeverityFFS + """)")
32        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>" + scSeverityFFS + """,tblGlobalData[Response Time],""PASS"")")
33        Call AddToArray(sFormulas, "=IF(tblOverall[[#This Row],[Total]]>0,tblOverall[[#This Row],[RespTm PASS]]/tblOverall[[#This Row],[Total]],0)")
34        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>" + scSeverityFFS + """,tblGlobalData[Resolution Time],""PASS"")")
35        Call AddToArray(sFormulas, "=IF(tblOverall[[#This Row],[Total]]>0,tblOverall[[#This Row],[ResolTm PASS]]/tblOverall[[#This Row],[Total]],0)")
36        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>" + scSeverityFFS + """,tblGlobalData[OVERALL],""PASS"")")
37        Call AddToArray(sFormulas, "=IF(tblOverall[[#This Row],[Total]]>0,tblOverall[[#This Row],[OVERALL PASS]]/tblOverall[[#This Row],[Total]],0)")
38        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>6"",tblGlobalData[ReWork],""Yes"")")
39        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>6"",tblGlobalData[Customer Satisfaction Rating],""Passed"")")
          ' SLA
40        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>" + scSeverityFFS + """,tblGlobalData[SLA],""<>"")")
41        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>" + scSeverityFFS + """,tblGlobalData[SLA],""<>"",tblGlobalData[Response Time],""PASS"")")
42        Call AddToArray(sFormulas, "=IF(tblOverall[[#This Row],[SLA Total]]>0,tblOverall[[#This Row],[SLA RespTm PASS]]/tblOverall[[#This Row],[SLA Total]],0)")
43        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>" + scSeverityFFS + """,tblGlobalData[SLA],""<>"",tblGlobalData[Resolution Time],""PASS"")")
44        Call AddToArray(sFormulas, "=IF(tblOverall[[#This Row],[SLA Total]]>0,tblOverall[[#This Row],[SLA ResolTm PASS]]/tblOverall[[#This Row],[SLA Total]],0)")
45        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>" + scSeverityFFS + """,tblGlobalData[SLA],""<>"",tblGlobalData[OVERALL],""PASS"")")
46        Call AddToArray(sFormulas, "=IF(tblOverall[[#This Row],[SLA Total]]>0,tblOverall[[#This Row],[SLA OVERALL PASS]]/tblOverall[[#This Row],[SLA Total]],0)")
47        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>" + scSeverityFFS + """,tblGlobalData[SLA],""<>"",tblGlobalData[ReWork],""Yes"")")
48        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>" + scSeverityFFS + """,tblGlobalData[SLA],""<>"",tblGlobalData[Customer Satisfaction Rating],""Passed"")")
          ' Non-SLA
49        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>" + scSeverityFFS + """,tblGlobalData[SLA],"""")")
50        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>" + scSeverityFFS + """,tblGlobalData[SLA],"""",tblGlobalData[Response Time],""PASS"")")
51        Call AddToArray(sFormulas, "=IF(tblOverall[[#This Row],[Non-SLA Total]]>0,tblOverall[[#This Row],[Non-SLA RespTm PASS]]/tblOverall[[#This Row],[Non-SLA Total]],0)")
52        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>" + scSeverityFFS + """,tblGlobalData[SLA],"""",tblGlobalData[Resolution Time],""PASS"")")
53        Call AddToArray(sFormulas, "=IF(tblOverall[[#This Row],[Non-SLA Total]]>0,tblOverall[[#This Row],[Non-SLA ResolTm PASS]]/tblOverall[[#This Row],[Non-SLA Total]],0)")
54        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>" + scSeverityFFS + """,tblGlobalData[SLA],"""",tblGlobalData[OVERALL],""PASS"")")
55        Call AddToArray(sFormulas, "=IF(tblOverall[[#This Row],[Non-SLA Total]]>0,tblOverall[[#This Row],[Non-SLA OVERALL PASS]]/tblOverall[[#This Row],[Non-SLA Total]],0)")
56        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>" + scSeverityFFS + """,tblGlobalData[SLA],"""",tblGlobalData[ReWork],""Yes"")")
57        Call AddToArray(sFormulas, "=COUNTIFS(tblGlobalData[RegOff],tblOverall[[#This Row],[RegOff]],tblGlobalData[Severity],""<>" + scSeverityFFS + """,tblGlobalData[SLA],"""",tblGlobalData[Customer Satisfaction Rating],""Passed"")")
58        With ThisWorkbook.Worksheets("Overall")
          
59            .Select
60            Range("A1").Select
              
              ' Fill column A with Header & Unique Values from tblGlobalData tables RegOff column.
61            Sheets("GlobalData").Range("tblGlobalData[[#Headers],[#Data],[RegOff]]").AdvancedFilter _
                             Action:=xlFilterCopy, CopyToRange:=Range("A1"), Unique:=True
              
              ' HEADINGS
62            iTotalCols = UBound(sHeadings) + 1
63            .Cells(iRow, iCol + 1).Resize(, iTotalCols).Value = sHeadings
64            Call CreateTable
              
              ' VALUES - Exclude FFS
65            On Error Resume Next
66            iTotalCols = UBound(sFormulas) + 1
67            .Cells(iRow + 1, iCol + 1).Resize(, iTotalCols).FormulaR1C1 = sFormulas
68            On Error GoTo Error_In_ExtraOverall
...

  • Home
  • VBA
  • Code


By Neil Derek, published on 23 Feb 2002
| Filed in

  • Comments
  • VBA

This extremely simple macro increments the value in a cell. You could use this for unique id’s on invoices, delivery notes, etc…


Sub Increment()
   ' change A1 to the cell you wish to increment
   Range("A1").Value = Range("A1").Value + 1
End Sub

You might also like…

Neil Derek

To add to Geoffrey’s answer about active cell — it would also require that you activate the sheet you are looking to input your values if it is a different sheet from the one that is currently active. Additionally you would have to activate a cell to use activecell and the activecell offset property.
For example

     'Activates the name of the sheet you would like to activate
    Sheets("Sheet2").Activate  

    'Activates cell A1
    Range("A1").Activate

    'Activates cell one row down, one column right
    ActiveCell.Offset(1,1).Select  

   'if current sheet is not activate you just do Sheets("Sheet2").Range("A1").Activate

The offset property of ActiveCell refers to other cells based off of the current active cell.

For example-

Offset(row,column) —

First Argument -Positive values as the first argument refer you to rows below the current active cell and Negative values refer you to rows above the current active cell

Second Argument-Positive values as the second argument refer you to columns right of the current active cell and Negative values refer you to columns left the current active cell


Форум программистов Vingrad

Новости ·
Фриланс ·
FAQ

Правила ·
Помощь ·
Рейтинг ·
Избранное ·
Поиск ·
Участники

Форум -> Компьютерные системы -> MS Office, Open Office и др. -> Программирование, связанное с MS Office
(еще)

Модераторы: mihanik

Поиск:

Ответ в темуСоздание новой темы
Создание опроса
> Как можно инкрементировать переменную на vba 

V

   

Опции темы

dizzy1984
Дата 16.3.2010, 15:49 (ссылка)
| (нет голосов)
Загрузка ... Загрузка …




Быстрая цитата

Цитата

Опытный
**

Профиль
Группа: Участник
Сообщений: 675
Регистрация: 15.2.2007

Репутация: нет
Всего: 25

Добрый день.
Допустим, у нас есть целочисленная переменная на vba:

Код

Dim a as Long

Можно ли ее как-то увеличить на 1-цу, не используя повторно ее имя.
Как бы это можно было сделать на c++ :

Код

a++;

На vb :

Код

Inc(a)

Есть ли что-то похожее на vba?

PM MAIL   Вверх
ViterAlex
Дата 16.3.2010, 15:53 (ссылка)
| (нет голосов)
Загрузка ... Загрузка …




Быстрая цитата

Цитата

Шустрый
*

Профиль
Группа: Участник
Сообщений: 94
Регистрация: 7.10.2009
Где: Харьков

Репутация: 7
Всего: 7

Нет такого в VBA. А что, религия не позволяет писать:

Код

a = a +1

?
А можно ещё функцию написать smile :

Код

Public Function Inc (n As Variant)
  Inc = n +1
End Function

PM MAIL WWW ICQ   Вверх
dizzy1984
Дата 17.3.2010, 16:33 (ссылка)
| (нет голосов)
Загрузка ... Загрузка …




Быстрая цитата

Цитата

Опытный
**

Профиль
Группа: Участник
Сообщений: 675
Регистрация: 15.2.2007

Репутация: нет
Всего: 25

Если переменная имеет длинное имя — код становится менее наглядным и более громоздким. С самописной функцией будут проблемы с переносимостью — когда захочешь куда-то добавить свой код нужно помнить о самописных библиотеках и т.п.

PM MAIL   Вверх



















Ответ в темуСоздание новой темы
Создание опроса
Правила форума «Программирование, связанное с MS Office»

mihanik

staruha

Запрещается!

1. Публиковать ссылки на вскрытые компоненты

2. Обсуждать взлом компонентов и делиться вскрытыми
компонентами


  • Несанкционированная реклама на форуме запрещена
  • Пожалуйста, давайте своим темам осмысленный, информативный заголовок. Вопль «Помогите!» таковым не является.
  • Чем полнее и яснее Вы изложите проблему, тем быстрее мы её решим.
  • Оставляйте свои записи в

    «Книге отзывов о работе администрации»

  • А вот тут лежит FAQ нашего подраздела


Если Вам понравилась атмосфера форума, заходите к нам чаще!

С уважением
mihanik и
staruha.

 

0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Программирование, связанное с MS Office | Следующая тема »

Подписаться на тему |
Подписка на этот форум |
Скачать/Распечатать тему

[ Время генерации скрипта: 0.0956 ]   [ Использовано запросов: 21 ]   [ GZIP включён ]

Реклама на сайте
   
Информационное спонсорство

Понравилась статья? Поделить с друзьями:
  • Increasing word spacing in word
  • Increasing numbers in excel
  • Increasing number in excel
  • Increase in value word
  • Increase bold in word