operate cells with other sheet with sheet().cells() format - vba

I need iterate sheets that plus values in their cells in other sheet, the names of the "sheets" are save in sheet().index= man_prov and i iterate that. The code works but appears a window that requets "refresh values to the sheets" and the objetive cell value finally is "#¿NAME?". The code is:
For k = pfila_mprov + 1 To ufila_mprov
sn = Sheets(man_prov).Cells(k, 2)
h = Sheets(sn).Index
Select Case k
Case ufila_mprov
suma = suma & " " & Sheets(h).Name & "!" & Sheets(h).Cells(4, 4).Address & ""
Case Else
suma = suma & " " & Sheets(h).Name & "!" & Sheets(h).Cells(4, 4).Address & ","
End Select
Next k
Sheets(pro_pack).Cells(16, 4).Formula = "=sum(" & suma & ")"
End If
i need use the format sheets().cell() to iterate, and finally plus the values saved in "suma" .
Thanks.

Related

Italicizing a specific part of a concatenation for a different worksheet

I am just beginning to experiment with VBA and wanted to create code that italicized the title of presentations in a concatenation, given that Excel normally does not allow that to happen. I also want to paste the output in another worksheet.
The current code is what I created to paste the concatenation output in a specific column of the SAME worksheet (named "Presentations Table"), but I am having trouble figuring out how to:
paste the concatenated output in a specific column of a different worksheet (named "Presentations Cited") starting from the first row and column in the same workbook
how to get it to automatically italicize ONLY the text from the title column. All other text in the concatenation should not be italicized.
I would be grateful for any help!
Table structure:
Current output:
Worksheets("Presentations Table").Range("a3", Worksheets("Presentations Table").Range("a3").End(xlDown)).Select
Row = 1
col = 1
For Each Cell In Selection
Authors = Cells(Row, col)
Year_Month = Cells(Row, col + 1)
Title = Cells(Row, col + 2)
Presentation_Type = Cells(Row, col + 3)
Event_Name = Cells(Row, col + 4)
Location = Cells(Row, col + 5)
Worksheets("Presentations Table").Cells(Row, col + 2) = Authors & " (" & Year_Month & "). " & Title & ". " & Presentation_Type & " at the " & Event_Name & ", " & Location & "."
Row = Row + 1
Next
You can paste them as HTML formatting with something like this (not tested):
Dim c As Range, s As String
Set c = ThisWorkbook.Worksheets("Presentations Table").Cells(3)
s = "<html>"
While c <> ""
s = s & c & " (" & c(, 2) & "). <i>" & c(, 3) & "</i>. " & c(, 4) & " at the " & c(, 5) & ", " & c(, 6) & ".</br>"
set c = c(2) ' the cell below c
Wend
With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
.SetText s
.PutInClipboard
End With
c(2).PasteSpecial

Getting a type mismatch error

I am getting a run-time error 13 'Type Mismatch' on this chunk of code and I cannot figure out why. I have not used the Mid() function before and that is the line that throws the error. Beginner here, any and all help appreciated.
I am wanting that if line to check to see if the third character in a string equals 4. If you know of a better way I am open to that as well.
For k = 2 To NRow
If Mid(SummarySheet.Range("B2:B" & k), 3, 3) = 4 Then
SummarySheet.Range("B" & k & ":D" & k).Cut
SummarySheet.Range("R" & k & ":T" & k).PasteSpecial xlPasteValues
End If
Next
I believe this is what you are trying to do:
You will need to iterate backwards through your data.
Mid only allows one cell at a time. And the third criterion is the length so it should be 1.
You can set the values then remove the data from the set.
For k = Nrow To 2 Step -1
If Mid(SummarySheet.Range("B" & k), 3, 1) = "4" Then
SummarySheet.Range("R" & k & ":T" & k).Value = SummarySheet.Range("B" & k & ":D" & k).Value
SummarySheet.Range("B" & k & ":D" & k).Delete xlshiftUp
End If
Next
Now if you only want to clear the values and keep a blank row in the data then use this:
For k = Nrow To 2 Step -1
If Mid(SummarySheet.Range("B" & k), 3, 1) = "4" Then
SummarySheet.Range("R" & k & ":T" & k).Value = SummarySheet.Range("B" & k & ":D" & k).Value
SummarySheet.Range("B" & k & ":D" & k).Clear
End If
Next
Mid() is used to get a substring of a single text value. Since you are trying this on an array, it will not work. I'm not completely sure this is what you want, but this should not throw an error:
If Mid(SummarySheet.Range("B" & k).Value, 3, 1) = "4" Then
Notice the reference is for a single cell, and the "4" is quoted to show that it's a string. I changed your last argument to 1 because you are looking for a single character.

VBA, concact 2 values with the same variable in cell

I'm trying to write a VBA script. This script would read 1 column and write the result in another column.
If the values are in bold or if is not blank, I would like to write the data in the column b1.
But if the values are not in bold, I would like to write the data in c1, and concatenate if I have 2 or more non-bold data in the same cell.
My code :
Sub Phone()
Dim valueLogon As String
Dim ValueDevice As String
Dim compteur As Integer
compteur = 1
For i = 1 To 2101
valueLogon = Range("A" & i)
If Range("A" & i).Font.bold = True And IsEmpty(valueLogon) = False Then
compteur = compteur + 1
Range("C" & i) = valueLogon
Else
Range("D" & compteur) = valueLogon & "," &
End If
Next i
End Sub
now, my result is like to the picture, but I would like concactenate the non-bold result in the same cell
change
Range("D" & compteur) = valueLogon & "," &
to
Range("D" & compteur).Value = valueLogon & "," & Range("D" & comptuer).Value

Inserting a formula into an array based on variables and offset function

I am trying to get my code to insert a formula into an array based on how many data points there are in my data set. The code below almost works but after the first iteration of X is complete it does not insert the formula into the all the rows in the columns.
Worksheets(" Branded").Range("C3").Formula = "=COUNTIFS(" & r.Address(ReferenceStyle:=xlR1C1) & ",RC2, " & r2.Address(ReferenceStyle:=xlR1C1) & ",R2C)"
For Y = 1 To Column_Limit1 - 1
Range("C3").Offset(0, Y).Formula = "=COUNTIFS(" & r.Address(ReferenceStyle:=xlR1C1) & ",RC2, " & r2.Address(ReferenceStyle:=xlR1C1) & ",R2C)"
For X = 1 To Row_Limit1 - 1
Range("C3").Offset(X, 0).Formula = "=COUNTIFS(" & r.Address(ReferenceStyle:=xlR1C1) & ",RC2, " & r2.Address(ReferenceStyle:=xlR1C1) & ",R2C)"
Next X
Next Y
Change to this:
With Worksheets(" Branded")
.Range(.Cells(3, 3), .Cells(Row_Limit1 + 2, Column_Limit1 + 2)).FormulaR1C1 = "=COUNTIFS(" & r.Address(ReferenceStyle:=xlR1C1) & ",RC2, " & r2.Address(ReferenceStyle:=xlR1C1) & ",R2C)"
.Range(.Cells(Row_Limit1 + 3, 3), .Cells(Row_Limit1 + 3, Column_Limit1 + 2)).FormulaR1C1 = "=SUM(R3C:R[-1]C)"
End With
When using R1C1 there is no need of a loop.

Fill a column from a concatenate range

What I have this far is below.
Range("F4").Value = Range("D4").Value & " x " & Range("E4")
This is creating a concatenate in Column F for me. This is working fine for the individual cell but I would like this to continue concatenating down until it hits an empty cell.
I have tried looping without success.
below is an image of the sheet
Set Concat= Rows(4)
concatstring =""
For i = 1 To Concat.Cells.Count
If Concat.Cells(i).Text <> "" Then
Concatstring = concatstring & " x " & Concat.Cells(i).Text
Else
Exit for
End If
Next
Concat.cells(I).text = concatstring
This should do it. Let me know if you still have problem.
Try this...
i=4
Do while(Range("D" & i).Value<> "")
Range("F" & i).Value = Range("D" & i).Value & " x " & Range("E" & i)
Loop