pcardenasm
New Member
- Joined
- Oct 28, 2023
- Messages
- 8
- Office Version
- 365
- Platform
- Windows
Hi,
I need some help to copy information from some sheets (only ph to Ortofosfatos,12 sheets) to BD. I've tried for one sheet, but i want to do the same with the other sheets in order, first ph, second Temperatura and so on. In sheet BD should be all the information from the other sheets (manually registered) with its format and must be updated (BD) every time data is entered in the other sheets. Headers in BD are fixed.
Excel file
TEP-EjBD-2023.xlsm
Thanks for considering my request.
Patricia CM
I need some help to copy information from some sheets (only ph to Ortofosfatos,12 sheets) to BD. I've tried for one sheet, but i want to do the same with the other sheets in order, first ph, second Temperatura and so on. In sheet BD should be all the information from the other sheets (manually registered) with its format and must be updated (BD) every time data is entered in the other sheets. Headers in BD are fixed.
Excel file
TEP-EjBD-2023.xlsm
VBA Code:
Sub CopyFosforo()
Dim cont As Long
Dim ultlinea As Long
Dim fecha As Date
Dim muestras As Variant
Dim analisis As Variant
Dim parametro As Variant
Dim tipo As Variant
Dim metodo As Variant
Dim influente As Variant
Dim MEnt As Variant
Dim MEntf As Variant
Dim MA As Variant
Dim MAf As Variant
Dim MB As Variant
Dim MBf As Variant
Dim MC As Variant
Dim MCf As Variant
Dim ML As Variant
Dim MLf As Variant
Dim m As Long
Dim y As Long
Dim EfluentTerc As Variant
Dim EfluentTercF As Variant
Dim rango As Variant
sheets("Fósforo").Select
Range("B12").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
sheets("BD").Select
Range("A3").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range("A3").Select
sheets("Fósforo").Select
Application.CutCopyMode = False
Range("B12").Select
ultlinea = sheets("BD").Range("A" & Rows.Count).End(xlUp).Row
fila = sheets("Fósforo").Range("B12").End(xlDown).Row
Set rango = sheets("Fósforo").Range("B12:N" & fila)
For cont = 3 To ultlinea
fecha = sheets("BD").Cells(cont, 1)
m = Month(fecha)
y = Year(fecha)
muestras = Application.VLookup(CLng(CDate(fecha)), rango, 2, False)
analisis = Application.VLookup(CLng(CDate(fecha)), rango, 3, False)
parametro = sheets("Fósforo").Name
tipo = Application.VLookup(CLng(CDate(fecha)), rango, 12, False)
metodo = Application.VLookup(CLng(CDate(fecha)), rango, 13, False)
EfluentTerc = Application.VLookup(CLng(CDate(fecha)), rango, 5, False)
If Application.WorksheetFunction.IsText(EfluentTerc) Then
EfluentTercF = Mid(EfluentTerc, 2, 4) / 2
Else
EfluentTercF = EfluentTerc
End If
MEnt = Application.VLookup(CLng(CDate(fecha)), rango, 6, False)
If Application.WorksheetFunction.IsText(MEnt) Then
MEntf = Mid(MEnt, 2, 4) / 2
Else
MEntf = MEnt
End If
MA = Application.VLookup(CLng(CDate(fecha)), rango, 7, False)
If Application.WorksheetFunction.IsText(MA) Then
MAf = Mid(MA, 2, 4) / 2
Else
MAf = MA
End If
MB = Application.VLookup(CLng(CDate(fecha)), rango, 8, False)
If Application.WorksheetFunction.IsText(MB) Then
MBf = Mid(MB, 2, 4) / 2
Else
MBf = MB
End If
MC = Application.VLookup(CLng(CDate(fecha)), rango, 9, False)
If Application.WorksheetFunction.IsText(MC) Then
MCf = Mid(MC, 2, 4) / 2
Else
MCf = MC
End If
ML = Application.VLookup(CLng(CDate(fecha)), rango, 10, False)
If Application.WorksheetFunction.IsText(ML) Then
MLf = Mid(ML, 2, 4) / 2
Else
MLf = ML
End If
If IsNumeric(MEntf) Then
influente = MEntf
If IsEmpty(MEntf) And IsNumeric(EfluentTercF) Then
influente = EfluentTercF
If IsEmpty(MEntf) And IsEmpty(EfluentTercF) Then
influente = MLf
End If
End If
End If
sheets("BD").Cells(cont, 2) = m
sheets("BD").Cells(cont, 3) = y
sheets("BD").Cells(cont, 4) = muestras
sheets("BD").Cells(cont, 5) = analisis
sheets("BD").Cells(cont, 6) = parametro
sheets("BD").Cells(cont, 7) = tipo
sheets("BD").Cells(cont, 8) = metodo
sheets("BD").Cells(cont, 9) = influente
sheets("BD").Cells(cont, 10) = MAf
sheets("BD").Cells(cont, 11) = MBf
sheets("BD").Cells(cont, 12) = MCf
sheets("BD").Cells(cont, 13) = MLf
Next cont
sheets("BD").Select
Range("A3").Select
MsgBox "Valores de fósforo copiados exitosamente", vbInformation, "Copiar"
End Sub
Thanks for considering my request.
Patricia CM
Last edited by a moderator: